4

Currently I am looking for ellegant solution to check that consumer groups in Redis stream already exist.

I have a few modules which connect to the same stream and read data from it. But they can start in different order and in case consumer groups is not created - try to create it. In case first module have created group, others get an error according to documentation.

From the documentation:

If the specified consumer group already exists, the command returns a -BUSYGROUP error.

I would like to avoid this error.

I use Jedis client for work with Redis. I know there is XINFO command (which can returns groups list), but it doesn't work when Redis was started in cluster mode (which can be one of my configuration).

Nazar Paruna
  • 121
  • 1
  • 7

1 Answers1

2

There is no other way, as you covered in your questions there are two options:

  1. XGROUP CREATE and catch an error in case the group is already there.
  2. XINFO STREAM and look for the group, but that won't be atomic and a parallel group create, might be called right after you get the info back.
Guy Korland
  • 9,139
  • 14
  • 59
  • 106
  • I opened an issue to improve this: https://github.com/redis/redis/issues/9893. The corresponding action in Kafka is idempotent and safe: https://docs.confluent.io/platform/current/clients/consumer.html – James A. Rosen Dec 04 '21 at 00:45