XREAD COUNT doesn't work with BLOCK
The documentation for XREAD https://redis.io/commands/xread mentions that you can issue XREAD with BLOCK and COUNT like this:
> XREAD BLOCK 5000 COUNT 100 STREAMS mystream $
My expectation would be that this waits max 5 seconds, but also waits for 100 messages in the stream. But when trying the following:
XREAD BLOCK 20000 COUNT 100 STREAMS tst $
The command returns back in redis cli after first XADD, and does not wait 20 seconds for other messages:
XADD tst * sensor-id 1234 temperature 19.8
...
> XREAD BLOCK 20000 COUNT 100 STREAMS tst $
1) 1) "tst"
2) 1) 1) "1541717154056-0"
2) 1) "sensor-id"
2) "1234"
3) "temperature"
4) "19.8"
(1.79s)
Is this the expected behaviour? Tried in Docker redis 5.0
Hello @hlavacek,
AFAIR, using BLOCK implicitly means COUNT 1 despite the docs' syntax.
At least a documentation issue then, same is true for XREADGROUP:
XREADGROUP GROUP mygroup asd COUNT 5 BLOCK 0 STREAMS mystream >
...
XADD mystream * sensor-id 1234 temperature 19
...
XREADGROUP GROUP mygroup asd COUNT 5 BLOCK 0 STREAMS mystream >
1) 1) "mystream"
2) 1) 1) "1541719198549-0"
2) 1) "sensor-id"
2) "1234"
3) "temperature"
4) "19"
(2.90s)
@itamarhaber So is this the expected behaviour then?
Yes, that is the expected behavior.
If the stream has 1 and up to 'count' messages, the read will return immediately w/o blocking and with as many messages as possible. If there are no messages, the block comes into effect and is released and returned once there is one message it can read, basically immediately after the XADD
@itamarhaber thanks for clarification!
case described in docs would be very interesting - wait COUNT records OR BLOCK seconds
This needs to be described in the docs.
Would appreciate a PR to that effect :)
Anyway, since this is seemingly a doc issue, moving to the doc repo.
this definitely needs to be described in the docs.