Skip to content

Instantly share code, notes, and snippets.

@xergio
Created December 7, 2011 11:11
Show Gist options
  • Save xergio/1442431 to your computer and use it in GitHub Desktop.
Save xergio/1442431 to your computer and use it in GitHub Desktop.
Python + Redis + PubSub
from python_redis_pubsub import TestPubsub
import time
if __name__ == "__main__":
test = TestPubsub()
print test.publish('test01', time.time())
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()
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