Skip to content

Instantly share code, notes, and snippets.

@dnmellen
Created January 15, 2014 15:37
Show Gist options
  • Save dnmellen/8438413 to your computer and use it in GitHub Desktop.
Save dnmellen/8438413 to your computer and use it in GitHub Desktop.
Listen Redis pubs with python3 and asyncio
import asyncio
import redis
@asyncio.coroutine
def listener(redis_conn, channels):
pubsub = redis_conn.pubsub()
pubsub.subscribe(channels)
print('Listening redis...')
for item in pubsub.listen():
print(item)
if __name__ == '__main__':
r = redis.Redis()
loop = asyncio.get_event_loop()
asyncio.Task(listener(r, ['test']))
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment