XINFO CONSUMERS

Introduction and Use Case(s)

The XINFO CONSUMERS command in Redis provides information about the consumers of a specific consumer group from a stream. It is useful for monitoring and debugging purposes, such as checking the status of various consumers within a group, identifying idle consumers, and understanding each consumer’s pending messages count.

Syntax

  1. XINFO CONSUMERS <key> <groupname>

Parameter Explanations

  • <key>: The name of the stream.
  • <groupname>: The name of the consumer group whose consumers you want to inspect.

Return Values

The command returns an array of information for each consumer in the specified consumer group. Each consumer’s details are provided as key-value pairs, including:

  • name: The name of the consumer.
  • pending: The number of pending messages for this consumer.
  • idle: The number of milliseconds since the consumer’s last attempted interaction with the stream.

Example Output

  1. 1) 1) "name"
  2. 2) "consumer-1"
  3. 3) "pending"
  4. 4) (integer) 5
  5. 5) "idle"
  6. 6) (integer) 1748237
  7. 2) 1) "name"
  8. 2) "consumer-2"
  9. 3) "pending"
  10. 4) (integer) 13
  11. 5) "idle"
  12. 6) (integer) 982374

Code Examples

  1. dragonfly> XGROUP CREATE mystream mygroup $ MKSTREAM
  2. OK
  3. dragonfly> XADD mystream * field1 value1
  4. "1688852531964-0"
  5. dragonfly> XADD mystream * field1 value2
  6. "1688852532964-0"
  7. dragonfly> XREADGROUP GROUP mygroup consumer-1 COUNT 1 STREAMS mystream >
  8. 1) 1) "mystream"
  9. 2) 1) 1) "1688852531964-0"
  10. 2) 1) "field1"
  11. 2) "value1"
  12. dragonfly> XREADGROUP GROUP mygroup consumer-2 COUNT 1 STREAMS mystream >
  13. 1) 1) "mystream"
  14. 2) 1) 1) "1688852532964-0"
  15. 2) 1) "field1"
  16. 2) "value2"
  17. dragonfly> XINFO CONSUMERS mystream mygroup
  18. 1) 1) "name"
  19. 2) "consumer-1"
  20. 3) "pending"
  21. 4) (integer) 1
  22. 5) "idle"
  23. 6) (integer) 15000
  24. 2) 1) "name"
  25. 2) "consumer-2"
  26. 3) "pending"
  27. 4) (integer) 1
  28. 5) "idle"
  29. 6) (integer) 10000

Best Practices

  • Regularly monitor the consumers using XINFO CONSUMERS to identify any potential bottlenecks or idle consumers.
  • Combine this command with other XINFO commands to get a comprehensive overview of your stream’s health and activity.

Common Mistakes

  • Misunderstanding the idle time as message age; it actually represents the time since the consumer last interacted with the stream.
  • Not specifying both the stream key and the consumer group name, which will result in an error.

FAQs

What does the idle value represent?

The idle value indicates the number of milliseconds that have elapsed since the consumer last attempted to read from the stream.

How can I reset a consumer’s idle time?

The idle time is reset whenever the consumer reads a message from the stream using commands like XREADGROUP.

Can I use XINFO CONSUMERS to monitor streams other than those with consumer groups?

No, XINFO CONSUMERS is specifically designed to provide information about consumers within a consumer group.