|
|
@@ -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)
|