#!/usr/bin/env python3 """Example of aiohttp.web.Application.on_startup signal handler""" import asyncio from contextlib import suppress from typing import AsyncIterator, List
async def on_shutdown(app: web.Application) -> None: for ws in app[websockets]:
await ws.close(code=999, message=b"Server shutdown")
async def listen_to_valkey(app: web.Application) -> None:
r = valkey.Valkey(host="localhost", port=6379, decode_responses=True)
channel = "news"
async with r.pubsub() as sub:
await sub.subscribe(channel)
async for msg in sub.listen(): if msg["type"] != "message": continue # Forward message to all connected websockets: for ws in app[websockets]:
await ws.send_str(f"{channel}: {msg}")
print(f"message in {channel}: {msg}")
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.