浏览代码

添加密码支持

vc5 7 年之前
父节点
当前提交
7449f7dabb
共有 4 个文件被更改,包括 14 次插入3 次删除
  1. 1 0
      Config.ini
  2. 2 1
      DB/DbClient.py
  3. 2 2
      DB/SsdbClient.py
  4. 9 0
      Util/GetConfig.py

+ 1 - 0
Config.ini

@@ -6,6 +6,7 @@ host = 127.0.0.1
 port = 6379
 ;port = 8888
 name = proxy
+#password = yourpassword
 
 [ProxyGetter]
 ;register the proxy getter function

+ 2 - 1
DB/DbClient.py

@@ -75,7 +75,8 @@ class DbClient(object):
         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)
+                                                          port=self.config.db_port,
+                                                          password=self.config.db_password)
 
     def get(self, key, **kwargs):
         return self.client.get(key, **kwargs)

+ 2 - 2
DB/SsdbClient.py

@@ -32,7 +32,7 @@ class SsdbClient(object):
 
     """
 
-    def __init__(self, name, host, port):
+    def __init__(self, name, **kwargs):
         """
         init
         :param name: hash name
@@ -41,7 +41,7 @@ class SsdbClient(object):
         :return:
         """
         self.name = name
-        self.__conn = Redis(connection_pool=BlockingConnectionPool(host=host, port=port))
+        self.__conn = Redis(connection_pool=BlockingConnectionPool(**kwargs))
 
     def get(self, proxy):
         """

+ 9 - 0
Util/GetConfig.py

@@ -45,6 +45,15 @@ class GetConfig(object):
     def db_port(self):
         return int(self.config_file.get('DB', 'port'))
 
+    @LazyProperty
+    def db_password(self):
+        try:
+            password = self.config_file.get('DB', 'password')
+        except Exception:
+            password = None
+        return password
+
+
     @LazyProperty
     def proxy_getter_functions(self):
         return self.config_file.options('ProxyGetter')