xreadgroup
XREADGROUP
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Read with a consumer group
Usage: XREADGROUP GROUP group consumer count 1 STREAMS key id-or->.
The last ID is usually the special ID '>' rather than a specific ID.
Each call then returns the next never-delivered entries.
Example
| Command> | XREADGROUP GROUP CG-A C1 count 1 STREAMS sensor-1234 > |
| Result> | 1) 1) "sensor-1234" 2) 1) 1) 1538319053569-0 2) 1) "temperature" 2) "98.7" |
| Command> | XREADGROUP GROUP CG-A C1 count 1 STREAMS sensor-1234 > |
| Result> | 1) 1) "sensor-1234" 2) 1) 1) 1538319053569-1 2) 1) "temperature" 2) "98.8" |
After XREADGROUP you must XACK when processing is complete.
BLOCK option
With BLOCK, if there is no data the command waits up to the given milliseconds.
- XREADGROUP GROUP group consumer count 1 BLOCK 1000 STREAMS key >
XREAD BLOCK uses '$' only on the first call; here you keep using '>'.
Several consumers on one stream
Several consumers can take turns on one stream. If there is a lot of work and processing is slow, assign multiple consumers.
- XREADGROUP GROUP CG-A Consumer-1 count 1 STREAMS sensor-1234 >
Result: temperature 100 - XREADGROUP GROUP CG-A Consumer-2 count 1 STREAMS sensor-1234 >
Result: temperature 101 - XREADGROUP GROUP CG-A Consumer-3 count 1 STREAMS sensor-1234 >
Result: temperature 102
Several streams
You can read from several streams.
- XREADGROUP GROUP CG-A Consumer-1 count 1 STREAMS sensor-1234 sensor-5678 > >
COUNT 1 then reads one entry from each stream.
Syntax
XREADGROUP GROUP group consumer
[COUNT count] [BLOCK milliseconds]
STREAMS key [key ...] ID [ID ...]
- Available since version 5.0.0.
- Time complexity is O(log(N)+M), where N is the number of stream entries and M is the number of entries returned.
| << XGROUP | XREADGROUP | XACK >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
