Created
October 28, 2019 07:40
-
-
Save toshihiroryuu/6b4a4b6dce604ce2003cf79fe74481e9 to your computer and use it in GitHub Desktop.
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
from multiprocessing.process import Process | |
import time | |
import redis | |
def pub(myredis): | |
for n in range(10): | |
myredis.publish('channel','blah %d' % n) | |
time.sleep(5) | |
def sub(myredis, name): | |
pubsub = myredis.pubsub() | |
pubsub.subscribe(['channel']) | |
for item in pubsub.listen(): | |
print '%s : %s' % (name, item['data']) | |
if __name__ == '__main__': | |
myredis = redis.Redis() | |
Process(target=pub, args=(myredis,)).start() | |
Process(target=sub, args=(myredis,'reader1')).start() | |
Process(target=sub, args=(myredis,'reader2')).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Redis Publisher and Subscribe mechanism for Python.