redis-doc icon indicating copy to clipboard operation
redis-doc copied to clipboard

XREAD COUNT doesn't work with BLOCK

Open hlavacek opened this issue 7 years ago • 9 comments

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

hlavacek avatar Nov 08 '18 23:11 hlavacek

Hello @hlavacek,

AFAIR, using BLOCK implicitly means COUNT 1 despite the docs' syntax.

itamarhaber avatar Nov 08 '18 23:11 itamarhaber

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)

hlavacek avatar Nov 08 '18 23:11 hlavacek

@itamarhaber So is this the expected behaviour then?

StasKolodyuk avatar Jun 07 '19 14:06 StasKolodyuk

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 avatar Jun 07 '19 20:06 itamarhaber

@itamarhaber thanks for clarification!

StasKolodyuk avatar Jun 07 '19 21:06 StasKolodyuk

case described in docs would be very interesting - wait COUNT records OR BLOCK seconds

dselivanov avatar Jul 18 '19 06:07 dselivanov

This needs to be described in the docs.

fubar avatar Dec 01 '20 21:12 fubar

Would appreciate a PR to that effect :)

Anyway, since this is seemingly a doc issue, moving to the doc repo.

itamarhaber avatar Dec 01 '20 21:12 itamarhaber

this definitely needs to be described in the docs.

mrajancsr avatar Apr 18 '22 13:04 mrajancsr