import redis from apistar import Component, Settings class RedisBackend: def __init__(self, settings: Settings) -> None: """ Configure a new redis backend Args: settings: The application settings dictionary """ redis_config = settings['REDIS'] self.host = redis_config.get('HOST') self.port = redis_config.get('PORT') self.password = redis_config.get('PASSWORD') # TODO add connection pooling class Client: def __init__(self, backend: RedisBackend): self.backend = backend def get_redis_client(backend: RedisBackend): """ Create a new redis session """ client = redis.Redis(host=backend.host, port=backend.port, password=backend.password) return client components = [ Component(RedisBackend), Component(Client, init=get_redis_client) ]