Skip to content

P?SUBSCRIPTIONS command: list current subscriptions #123

Closed

Description

@dominictarr

I've am writing a redis client for nodejs, and the trickiest thing is dealing with P?UNSUBSCRIBE replys.

the difficulty is that P?UNSUBSCRIBE makes many replies, so it is necessary to calculate how many replys I should expect,
by keeping a count of the number of current subscriptions, so that when the user asks to UNSUBSCRIBE I can pass them the correct list of channels/patterns that they are subscribed to.

Idealy, I think it's simpler if P?UNSUBSCRIBE does a regular MultiBulk reply, but as that would be a breaking API change, A work around could be a P?SUBSCRIPTIONS command, that would have the same semantics as P?UNSUBSCRIBE but instead reply with a list of channels that would be unsubscribed if you passed the same arguments to P?UNSUBSCRIBE.

Activity

  1. antirez commented on Oct 10, 2011

    @antirez
    Contributor

    Hello, I don't understand very well the issue. Both UNSUBCRIBE and PUNSUBSCRIBE will just emit a single message.
    Maybe you used to think that PUNSUBSCRIBE would emit a message for every matching channel?

  2. dominictarr commented on Oct 11, 2011

    @dominictarr
    Author

    hi, thanks for responding,
    this is what I am seeing:

    dominic@dominic:~$ nc localhost 6379
    PSUBSCRIBE x j q
    *3
    $10
    psubscribe
    $1
    x
    :1
    *3
    $10
    psubscribe
    $1
    j
    :2
    *3
    $10
    psubscribe
    $1
    q
    :3
    

    that is three separate replies, correct?

    then when you unsubscribe, without args it will emit a message for each pattern:

    dominic@dominic:~$ nc localhost 6379
    PSUBSCRIBE x j q
    *3
    $10
    psubscribe
    $1
    x
    :1
    *3
    $10
    psubscribe
    $1
    j
    :2
    *3
    $10
    psubscribe
    $1
    q
    :3
    

    what I do is count the number of patterns that the user has subscribed to, then if they send an unsubscribe command I will know how many responses there should be.

    I'm not sure how to tell what redis version I am on. I'm on ubuntu and installed it via apt-get. is this behavior different in a new version?

    please tell me if there is an important reason that pubsub behaves like this.

    cheers, Dominic

  3. added a commit that references this issue on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions