redis / go-redis

Redis Go client
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
19.81k stars 2.34k forks source link

Add comment for XReadGroupArgs to note the inconsistency of the default behavior between Redis & go-redis #2851

Closed tzq0301 closed 8 months ago

tzq0301 commented 8 months ago

As mentioned in issue 1941, the default behavior between Redis and go-redis is inconsistent.

In Redis, the default behavior of XREADGROUP is non-blocking (without setting the value of [BLOCK milliseconds].

Therefore, it is natural to think of ignoring the setting of field Block in XReadGroupArgs, which means the value of Block in XReadGroupArgs will be the zero-value of time.Duration.

However, in the implementation of go-redis, from the perspective of the function func (cmdable) XReadGroup(...), it doesn't know if the user set the Block's value to 0, or if the user didn't set the Block's value causing Go to assign a zero-value to the Block.

But go-redis ignores the possible ambiguity and just take the arg as [BLOCK 0], whick blocks our program as mentioned in issue 1941.

if a.Block >= 0 {
  args = append(args, "block", int64(a.Block/time.Millisecond))
  keyPos += 2
}

In the event that we can't need to ensure API compatibility, we can only add comments to the Block.