Open patrick-janeiro opened 2 years ago
I am writing unit tests to test our pipeline code. We ran into an issue that a BeforePipelineProcess hook is propagating the first error to all CMDs.
BeforePipelineProcess
Example code:
` redisDB, redisMock := redismock.NewClientMock() redisMock.ExpectGet("key1").SetErr(Errors.New("error")) redisMock.ExpectGet("key2").SetVal("{\"key\":\"key2\",\"value\":\"value2\"}")
`
when using this setup for my mock client with the following code:
pipeline := c.client.Pipeline() defer pipeline.Close() redisResults := make([]*redis.StringCmd, len(keys)) for i, key := range keys { redisResults[i] = pipeline.Get(ctx, key) } _, _ = pipeline.Exec(ctx)
I see that redisResults has "error" for all stringCmd results, instead of just the first CMD for key1.
key1
We tested the same code with a redis instance and got the expected result of the first cmd returning an error but the second being nil.
I experience the same error
this problem is made by the go-redis, take a look at code here
I am writing unit tests to test our pipeline code. We ran into an issue that a
BeforePipelineProcess
hook is propagating the first error to all CMDs.Example code:
` redisDB, redisMock := redismock.NewClientMock() redisMock.ExpectGet("key1").SetErr(Errors.New("error")) redisMock.ExpectGet("key2").SetVal("{\"key\":\"key2\",\"value\":\"value2\"}")
`
when using this setup for my mock client with the following code:
pipeline := c.client.Pipeline() defer pipeline.Close() redisResults := make([]*redis.StringCmd, len(keys)) for i, key := range keys { redisResults[i] = pipeline.Get(ctx, key) } _, _ = pipeline.Exec(ctx)
I see that redisResults has "error" for all stringCmd results, instead of just the first CMD for
key1
.We tested the same code with a redis instance and got the expected result of the first cmd returning an error but the second being nil.