go-redis / redismock

Redis client Mock
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
280 stars 60 forks source link

fix: cmd error in pipelines #90

Closed jonasmeier1212 closed 3 months ago

jonasmeier1212 commented 3 months ago

When a command in a pipeline produces an error, only this single command should fail and return an error.

However the currently implemented behavior is that the complete pipeline execution fails, which isn't resembling the behavior from Redis.

Example:


func toBeTested(redis *redis.Client) {
  pipe := redis.Pipeline()

  pipe.Get("key1")
  pipe.Get("key2")

  cmds, err := pipe.Exec()
  // The behavior of Redis is that `err=nil`, although the seconds command will return a `redis.Nil` error.
  // cmds[1].Err() should be `redis.Nil`
  // The redismock implemention however returns already here `redis.Nil` error, which is wrong behavior. 
}

func Test_1(t *testing.T) {
  redisClient, mock := redismock.NewClientMock()

  mock.ExpectGet("key1").SetVal("val1")
  mock.ExpectGet("key2").RedisNil()

  toBeTested(redisClient)
}
jonasmeier1212 commented 3 months ago

Actually that's the real behavior of go-redis: https://github.com/redis/go-redis/issues/1860

So this PR is irrelevant and wrong.