XINFO STREAM

Introduction and Use Case(s)

XINFO STREAM provides detailed information about a Redis stream, including the length of the stream, the first and last entry IDs, and various other statistics. It is typically used for monitoring, debugging, and understanding the state of a Redis stream.

Syntax

  1. XINFO STREAM <key>

Parameter Explanations

  • <key>: The name of the stream to retrieve information from. This parameter is required.

Return Values

The command returns a list of key-value pairs representing various pieces of information about the stream. For example:

  • length: The number of entries in the stream.
  • radix-tree-keys: Number of radix tree nodes.
  • radix-tree-nodes: Number of radix tree nodes.
  • groups: Number of consumer groups associated with the stream.
  • last-generated-id: The ID of the last entry added to the stream.
  • first-entry and last-entry: Details of the first and last entries, respectively.

Example output:

  1. 1) "length"
  2. 2) (integer) 10
  3. 3) "radix-tree-keys"
  4. 4) (integer) 5
  5. 5) "radix-tree-nodes"
  6. 6) (integer) 10
  7. 7) "groups"
  8. 8) (integer) 2
  9. 9) "last-generated-id"
  10. 10) "1609459200000-0"
  11. 11) "first-entry"
  12. 12) 1) "1609459200000-0"
  13. 2) 1) "field1"
  14. 2) "value1"
  15. 13) "last-entry"
  16. 14) 1) "1609459201000-0"
  17. 2) 1) "field2"
  18. 2) "value2"

Code Examples

  1. dragonfly> XADD mystream * field1 value1
  2. "1609459200000-0"
  3. dragonfly> XADD mystream * field2 value2
  4. "1609459201000-0"
  5. dragonfly> XINFO STREAM mystream
  6. 1) "length"
  7. 2) (integer) 2
  8. 3) "radix-tree-keys"
  9. 4) (integer) 1
  10. 5) "radix-tree-nodes"
  11. 6) (integer) 2
  12. 7) "groups"
  13. 8) (integer) 0
  14. 9) "last-generated-id"
  15. 10) "1609459201000-0"
  16. 11) "first-entry"
  17. 12) 1) "1609459200000-0"
  18. 2) 1) "field1"
  19. 2) "value1"
  20. 13) "last-entry"
  21. 14) 1) "1609459201000-0"
  22. 2) 1) "field2"
  23. 2) "value2"

Best Practices

  • Regularly monitor your streams using XINFO STREAM to ensure they are functioning as expected and to identify any potential issues early on.
  • Use this command alongside other stream commands to gain a comprehensive view of stream health and performance.

Common Mistakes

  • Forgetting that the key parameter is mandatory. Always specify the stream key you want to inspect.
  • Misinterpreting the output structure; ensure correct parsing to extract meaningful data.

FAQs

Why does XINFO STREAM return zero groups even though I have consumers reading from the stream?

XINFO STREAM shows the number of consumer groups, not individual consumers. Ensure you have created consumer groups explicitly using XGROUP CREATE.

Can XINFO STREAM be used to check if a stream exists?

Yes, if the stream does not exist, XINFO STREAM will return an error, indicating the stream’s absence.