You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from redis import StrictRedis as Client
|
|
|
|
|
|
|
|
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
|
|
|
|
# TODO serialization of strings in the connector settings
|
|
|
|
|
|
|
|
|
|
|
|
def get_redis_client(backend: RedisBackend):
|
|
|
|
"""
|
|
|
|
Create a new redis client session
|
|
|
|
|
|
|
|
"""
|
|
|
|
client = Client(host=backend.host,
|
|
|
|
port=backend.port,
|
|
|
|
password=backend.password)
|
|
|
|
return client
|
|
|
|
|
|
|
|
|
|
|
|
components = [
|
|
|
|
Component(RedisBackend),
|
|
|
|
Component(Client, init=get_redis_client)
|
|
|
|
]
|