XREAD

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Read entries

Usage: XREAD count 1 STREAMS key ID.

Example

Command>XREAD count 1 STREAMS sensor-1234 0
Result>1) 1) "sensor-1234"
    2) 1) 1) 1538319053569-0
            2) 1) "temperature"
                2) "98.7"
Command>XREAD count 1 STREAMS sensor-1234 1538319053569-0
Result>1) 1) "sensor-1234"
    2) 1) 1) 1538319053569-1
            2) 1) "temperature"
                2) "98.8"
  • Reads entries with an ID greater than the given ID. Unlike XRANGE you do not need to add 1, so iteration is easier.
  • Unlike XRANGE you can specify several keys.
    XREAD count 1 STREAMS sensor-1234 sensor-5678 0 0
    COUNT is per key.

BLOCK option

This is similar to BLPOP on lists. Usage:

Example

Command>XREAD count 1 block 1000 STREAMS sensor-1234 $
Result>1) 1) "sensor-1234"
    2) 1) 1) 1538319053569-0
            2) 1) "temperature"
                2) "98.7"
Command>XREAD count 1 block 1000 STREAMS sensor-1234 1538319053569-0
Result>1) 1) "sensor-1234"
    2) 1) 1) 1538319053569-1
            2) 1) "temperature"
                2) "98.8"
  • BLOCK takes milliseconds to wait for matching entries.
  • For the first read, the special ID $ is recommended. It reads entries that arrive after this command.

Syntax

XREAD [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.

<< XREVRANGE XREAD XDEL >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.