vfclcm upgrade from python2 to python3
[vfc/gvnfm/vnflcm.git] / lcm / lcm / pub / redisco / __init__.py
diff --git a/lcm/lcm/pub/redisco/__init__.py b/lcm/lcm/pub/redisco/__init__.py
new file mode 100644 (file)
index 0000000..7d59d8d
--- /dev/null
@@ -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']