Redis publish/subscribe: see what channels are currently subscribed to

后端 未结 5 1660
Happy的楠姐
Happy的楠姐 2021-02-05 14:37

I am currently interested in seeing what channels are subscribed to in a Redis pub/sub application I have. When a client connects to our server, we register them to a channel th

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 14:40

    I am unaware of any specific way to query what channels are being subscribed to, and you are correct that there isn't any key created when this happens. Also, I wouldn't use the KEYS command in production anyway, as it's really a debugging command.

    You have the right idea about using a set to add the user when they're online, and then query this with SISMEMBER to determine if the messages should be sent to them or added to a Redis list for processing once they do come online.

    You will need to figure out when a user logs off so you can remove them from the list of online users, but I don't know enough about your system to know exactly how you would go about that.

    If the connected clients have the ability to send a message back to inform the server that the message(s) were consumed, you could use this to keep track of which messages should be stored for later retrieval.

    Cheers, Mike

提交回复
热议问题