vfclcm upgrade from python2 to python3
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / redisco / __init__.py
1 # -*- coding: utf-8 -*-
2
3 import redis
4
5
6 class Client(object):
7     def __init__(self, **kwargs):
8         self.connection_settings = kwargs or {'host': 'localhost', 'port': 6379, 'db': 0}
9
10     def redis(self):
11         return redis.Redis(**self.connection_settings)
12
13     def update(self, d):
14         self.connection_settings.update(d)
15
16
17 def connection_setup(**kwargs):
18     global connection, client
19     if client:
20         client.update(kwargs)
21     else:
22         client = Client(**kwargs)
23     connection = client.redis()
24
25
26 def get_client():
27     global connection
28     return connection
29
30
31 client = Client()
32 connection = client.redis()
33
34 __all__ = ['connection_setup', 'get_client']