Created
December 7, 2011 11:11
-
-
Save xergio/1442431 to your computer and use it in GitHub Desktop.
Python + Redis + PubSub
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 python_redis_pubsub import TestPubsub | |
import time | |
if __name__ == "__main__": | |
test = TestPubsub() | |
print test.publish('test01', time.time()) |
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
import redis | |
class TestPubsub(object): | |
def __init__(self): | |
self._conn = redis.StrictRedis(connection_pool=redis.ConnectionPool()) | |
self._pubsub = self._conn.pubsub() | |
def subscribe(self, key): | |
return self._pubsub.subscribe(key) | |
def publish(self, key, value): | |
return self._conn.publish(key, value) | |
def listen(self): | |
return self._pubsub.listen() |
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 python_redis_pubsub import TestPubsub | |
if __name__ == "__main__": | |
test = TestPubsub() | |
test.subscribe('test01') | |
for item in test.listen(): | |
print item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment