How to check consumer group already exists in Redis?

Viewed 2462

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).

1 Answers

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.
Related