问题
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