Created
January 15, 2014 15:37
-
-
Save dnmellen/8438413 to your computer and use it in GitHub Desktop.
Listen Redis pubs with python3 and asyncio
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 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