jhao104 пре 9 година
родитељ
комит
47e6919835
7 измењених фајлова са 79 додато и 22 уклоњено
  1. 5 4
      Config.ini
  2. 19 13
      DB/DbClient.py
  3. 4 4
      DB/SsdbClient.py
  4. 24 0
      Manager/ProxyManager.py
  5. 13 0
      Manager/__init__.py
  6. 1 1
      Util/utilFunction.py
  7. 13 0
      __init__.py

+ 5 - 4
Config.ini

@@ -1,5 +1,6 @@
+
 [DB]
-type=SSDB
-host=localhost
-port=8080
-name= proxy
+type = SSDB
+host = localhost
+port = 8080
+name = proxy

+ 19 - 13
DB/DbClient.py

@@ -12,41 +12,47 @@
 """
 __author__ = 'JHao'
 
+from Util.GetConfig import GetConfig
+
 
 class DbClient(object):
     """
     DbClient
     """
-    def __init__(self, db_type, name, host='localhost', port=8080, **kwargs):
+
+    def __init__(self):
         """
         init
-        :param db_type: DB type
-        :param name:
-        :param host:
-        :param port:
-        :param kwargs:
         :return:
         """
+        self.config = GetConfig()
+        self.__initDbClient()
 
+    def __initDbClient(self):
+        """
+        init DB Client
+        :return:
+        """
         __type = None
-        if "ssdb" in db_type.lower():
+        if "SSDB" == self.config.db_type:
             __type = "SsdbClient"
         else:
             pass
-        assert __type, 'type error, Not support DB type: {}'.format(db_type)
-
-        self.client = getattr(__import__(__type), __type)(name=name, host=host, port=port, **kwargs)
+        assert __type, 'type error, Not support DB type: {}'.format(self.config.db_type)
+        self.client = getattr(__import__(__type), __type)(name=self.config.db_name,
+                                                          host=self.config.db_host,
+                                                          port=self.config.db_port)
 
     def get(self, **kwargs):
         return self.client.get(**kwargs)
 
-    def put(self, **kwargs):
-        return self.client.put(**kwargs)
+    def put(self, value, **kwargs):
+        return self.client.put(value, **kwargs)
 
     def pop(self, **kwargs):
         return self.client.pop(**kwargs)
 
 
 if __name__ == "__main__":
-    account = DbClient('SSDB').pop()
+    account = DbClient().pop()
     print(account)

+ 4 - 4
DB/SsdbClient.py

@@ -33,7 +33,7 @@ class SsdbClient(object):
         self.name = name
         self.__conn = SSDB(connection_pool=BlockingConnectionPool(host=host, port=port))
 
-    def get(self):
+    def get(self, **kwargs):
         """
         get an item from the queue front
         :return:
@@ -41,16 +41,16 @@ class SsdbClient(object):
         value = self.__conn.qfront(name=self.name)
         return value
 
-    def put(self, value):
+    def put(self, value, **kwargs):
         """
         put an  item in the back of a queue
         :param value:
         :return:
         """
         value = json.dump(value, ensure_ascii=False).encode('utf-8') if isinstance(value, (dict, list)) else value
-        return self.__conn.qpush_back(value)
+        return self.__conn.qpush_back(self.name, value, **kwargs)
 
-    def pop(self):
+    def pop(self, **kwargs):
         """
         pop an item from the queue front
         :return:

+ 24 - 0
Manager/ProxyManager.py

@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+"""
+-------------------------------------------------
+   File Name:     ProxyManager.py  
+   Description :  
+   Author :       JHao
+   date:          2016/12/3
+-------------------------------------------------
+   Change Activity:
+                   2016/12/3: 
+-------------------------------------------------
+"""
+__author__ = 'JHao'
+
+from DB.DbClient import DbClient
+
+
+class ProxyManager(object):
+    """
+    ProxyManager
+    """
+
+    def __init__(self):
+        self.db = DbClient

+ 13 - 0
Manager/__init__.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+"""
+-------------------------------------------------
+   File Name:     __init__.py.py  
+   Description :  
+   Author :       JHao
+   date:          2016/12/3
+-------------------------------------------------
+   Change Activity:
+                   2016/12/3: 
+-------------------------------------------------
+"""
+__author__ = 'JHao'

+ 1 - 1
Util/utilFunction.py

@@ -2,7 +2,7 @@
 """
 -------------------------------------------------
    File Name:     utilFunction.py  
-   Description :  工具函数
+   Description :  tool function
    Author :       JHao
    date:          2016/11/25
 -------------------------------------------------

+ 13 - 0
__init__.py

@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+"""
+-------------------------------------------------
+   File Name:     __init__.py  
+   Description :  
+   Author :       JHao
+   date:          2016/12/3
+-------------------------------------------------
+   Change Activity:
+                   2016/12/3: 
+-------------------------------------------------
+"""
+__author__ = 'JHao'