Skip to content

Instantly share code, notes, and snippets.

@lbatteau
Last active January 18, 2021 20:23
Show Gist options
  • Save lbatteau/d02a0ea8746ca9416286c32e642c9689 to your computer and use it in GitHub Desktop.
Save lbatteau/d02a0ea8746ca9416286c32e642c9689 to your computer and use it in GitHub Desktop.
subscribe.py
async def subscribe(channel: str, redis: Redis) -> AsyncGenerator:
(subscription,) = await redis.subscribe(channel=Channel(channel, False))
while await subscription.wait_message():
yield {"event": "message", "data": await subscription.get()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment