예제 #1
0
async def create_redis_room_store(redis: Redis) -> RedisRoomStore:
    (append_to_room, lreplace, delete_room) = await asyncio.gather(
        redis.script_load(_APPEND_TO_ROOM),
        redis.script_load(_LREPLACE),
        redis.script_load(_DELETE_ROOM),
    )

    return RedisRoomStore(redis, append_to_room, lreplace, delete_room)
예제 #2
0
async def create_redis_rate_limiter(server_id: str,
                                    redis: Redis) -> RedisRateLimiter:
    server_key = f'api-server:{server_id}'
    initialize_futures = [
        redis.script_load(_ACQUIRE_CONNECTION_SLOT),
        redis.script_load(_RELEASE_CONNECTION_SLOT),
        redis.script_load(_INCR_AND_EXPIRE_IF_NEW),
        redis.set(server_key, 'true'),
        redis.expire(server_key, SERVER_LIVENESS_EXPIRATION_SECONDS),
    ]
    [acquire_sha, release_sha, incr_expire_sha,
     *_] = await asyncio.gather(*initialize_futures)

    return RedisRateLimiter(
        server_id,
        redis,
        acquire_connection_sha=acquire_sha,
        release_connection_sha=release_sha,
        incr_expire_sha=incr_expire_sha,
    )