XGROUP

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

Consumer groups

A consumer group lets you read as a named consumer, check whether that consumer processed the data, and reassign unprocessed entries to another consumer.

XGROUP supports:

  • Create a consumer group
  • Destroy a consumer group
  • Delete a consumer
  • Reset the last ID

Create a consumer group

Usage: XGROUP CREATE key group id-or-$.

Example

Command>XGROUP CREATE sensor-1234 CG-A 0
Command>XGROUP CREATE sensor-1234 CG-B 1538568728545
Command>XGROUP CREATE sensor-1234 CG-C $
  • The first command names the group CG-A and sets ID 0 so it reads from the first entry of sensor-1234.
  • The second names the group CG-B and starts after a specific ID.
  • The third uses the special ID '$' so it only reads entries that arrive after this command.
  • Returns OK on success.

Destroy a consumer group

Destroys the group even if it still has pending entries.
Usage: XGROUP DESTROY key group.

Example

Command>XGROUP DESTROY sensor-1234 CG-A

Returns 1 if the group was deleted, 0 if the group does not exist.

Delete a consumer

Deletes a consumer. Consumers are created automatically when named in XREADGROUP.
Usage: XGROUP DELCONSUMER key group consumer.

Example

Command>XGROUP DELCONSUMER sensor-1234 CG-A consumer

Returns the number of pending entries that consumer had. Returns 0 if there were none, or if the consumer does not exist.

Reset the last ID

Sets the ID from which XREADGROUP will continue. The initial ID is set by XGROUP CREATE.
Usage: XGROUP SETID key group id-or-$.

Example

Command>XGROUP SETID sensor-1234 CG-A 0
Command>XGROUP SETID sensor-1234 CG-A 1538568728545
Command>XGROUP SETID sensor-1234 CG-A $

Returns OK on success.


Syntax

XGROUP
[CREATE key group id-or-$]
[DESTROY key group]
[DELCONSUMER key group consumer]
[SETID key group id-or-$]

  • Available since version 5.0.0.
  • Time complexity is O(log(N)), where N is the number of entries in the stream.
    DESTROY is extra O(M) if there are pending entries to remove.
  • The return value depends on the subcommand.

<< XTRIM XGROUP XREADGROUP >>

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