DbClient.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: DbClient.py
  5. Description : DB工厂类
  6. Author : JHao
  7. date: 2016/12/2
  8. -------------------------------------------------
  9. Change Activity:
  10. 2016/12/2:
  11. -------------------------------------------------
  12. """
  13. __author__ = 'JHao'
  14. from Util.GetConfig import GetConfig
  15. class DbClient(object):
  16. """
  17. DbClient
  18. """
  19. def __init__(self):
  20. """
  21. init
  22. :return:
  23. """
  24. self.config = GetConfig()
  25. self.__initDbClient()
  26. def __initDbClient(self):
  27. """
  28. init DB Client
  29. :return:
  30. """
  31. __type = None
  32. if "SSDB" == self.config.db_type:
  33. __type = "SsdbClient"
  34. else:
  35. pass
  36. assert __type, 'type error, Not support DB type: {}'.format(self.config.db_type)
  37. self.client = getattr(__import__(__type), __type)(name=self.config.db_name,
  38. host=self.config.db_host,
  39. port=self.config.db_port)
  40. def get(self, **kwargs):
  41. return self.client.get(**kwargs)
  42. def put(self, value, **kwargs):
  43. return self.client.put(value, **kwargs)
  44. def pop(self, **kwargs):
  45. return self.client.pop(**kwargs)
  46. if __name__ == "__main__":
  47. account = DbClient().pop()
  48. print(account)