INNER CODE UNIT · Python

lifespan

leonh/redis-streams-fastapi-chat · chat.py:49

async def lifespan(app: FastAPI):
    # Startup
    try:
        redis_url = f"redis://{REDIS_HOST}:{REDIS_PORT}"
        pool = await aioredis.from_url(
            redis_url,
            encoding='utf-8',
            decode_responses=True,
            max_connections=20
        )
        cvar_redis.set(pool)
        print("Connected to Redis on ", REDIS_HOST, REDIS_PORT)
    except ConnectionRefusedError as e:
        print('cannot connect to redis on:', REDIS_HOST, REDIS_PORT)

    yield

    # Shutdown

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…