Last active
June 7, 2017 07:30
-
-
Save vireshas/9b6705eecd1fcb20b97506a6ddb7bb6e to your computer and use it in GitHub Desktop.
IPCs using Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Publisher: | |
# Persist message in a queue | |
lpush channel1.queue message | |
# Publish message to any connected subscriber | |
publish channel1 message | |
Subscriber: | |
# Subscribe to channel1 | |
subscribe channel1 | |
# Process any persisted messages | |
brpop channel1.queue | |
### Edit: Another solution, where publisher only stores messages if there was no subscriber: | |
Publisher: | |
subscribers = publish channel1 message | |
if subscribers == 0 | |
lpush channel1.queue message | |
Subscriber: | |
# handle stored messages | |
while(message = rpop channel1.queue) | |
# process message | |
# subscribe for new messages | |
subscribe channel1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment