Skip to content

Instantly share code, notes, and snippets.

@whitespy
Created January 23, 2025 14:03
Show Gist options
  • Select an option

  • Save whitespy/cbe8b38122ff83bc0500cd2ba1ecb4df to your computer and use it in GitHub Desktop.

Select an option

Save whitespy/cbe8b38122ff83bc0500cd2ba1ecb4df to your computer and use it in GitHub Desktop.
pubsub.py
async with app["redis_connection"].pubsub() as pubsub:
await pubsub.psubscribe("applicants:*")
try:
while True:
message = await pubsub.get_message(ignore_subscribe_messages=True)
if message is not None:
for ws in app["websockets"].get(message["channel"], []):
if not ws.closed:
await ws.send_json(message["data"])
except asyncio.CancelledError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment