diff options
Diffstat (limited to 'lcm/pub/redisco/__init__.py')
-rw-r--r-- | lcm/pub/redisco/__init__.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lcm/pub/redisco/__init__.py b/lcm/pub/redisco/__init__.py new file mode 100644 index 00000000..7d59d8d5 --- /dev/null +++ b/lcm/pub/redisco/__init__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +import redis + + +class Client(object): + def __init__(self, **kwargs): + self.connection_settings = kwargs or {'host': 'localhost', 'port': 6379, 'db': 0} + + def redis(self): + return redis.Redis(**self.connection_settings) + + def update(self, d): + self.connection_settings.update(d) + + +def connection_setup(**kwargs): + global connection, client + if client: + client.update(kwargs) + else: + client = Client(**kwargs) + connection = client.redis() + + +def get_client(): + global connection + return connection + + +client = Client() +connection = client.redis() + +__all__ = ['connection_setup', 'get_client'] |