0

I want to check how many users are connected to my pubsub pattern. Is there a simple way to do it in Go? Thank you.

    pubsub := env.redisCli.PSubscribe(name)
    defer pubsub.Close()

I have tried this:

val, _ := env.redisCli.Do("pubsub", "numpat").Int()

But it shows me other patterns also and I want to count only in that specific pattern.

Rogalek
  • 50
  • 10

1 Answers1

0

The redis documentation states you can limit the result to a single subscription with the NUMSUB command, but this will not list clients that are subscribed to patterns:

Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.

The NUMPAT on the other hand will count all patterns all clients are connected to:

Note that this is not just the count of clients subscribed to patterns but the total number of patterns all the clients are subscribed to.

(from https://redis.io/commands/pubsub)

I don't find a way to list all subscribers with their subscriptions in Redis. So the only way I can think of is to store that information in redis (or somewhere else) independently and manage it yourself.

TehSphinX
  • 6,536
  • 1
  • 24
  • 34