Redis Pub/Sub - Publisher also a subscriber?

心不动则不痛 提交于 2021-02-10 19:11:43

问题


I'm new to Redis, and I've been messing around with the Pub/Sub. Due to dependency factors, I would like the publisher to also be the subscriber of a channel, such that when the publisher sends a message through the channel, they also receive the message. Is this possible?


回答1:


No it is not possible with pub/sub because there is no persistence. When the publisher publishes the message to a channel, only the connected clients of the channel will receive the message. No message will be saved. Since your publisher will not be connected as subscriber, you can't receive what you published before. Even a subscriber looses connection and connects back, he will not receive the messages while he was disconnected.

There are some workarounds such as whenever you publish a message, you may send it to a sorted set/list and read it later.

Another way to do it maybe using keyspace notifications but didn't try it. You may check the details here



来源:https://stackoverflow.com/questions/62250119/redis-pub-sub-publisher-also-a-subscriber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!