DbClient.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. import os
  15. import sys
  16. from Util.GetConfig import GetConfig
  17. sys.path.append(os.path.dirname(os.path.abspath(__file__)))
  18. class DbClient(object):
  19. """
  20. DbClient
  21. """
  22. def __init__(self):
  23. """
  24. init
  25. :return:
  26. """
  27. self.config = GetConfig()
  28. self.__initDbClient()
  29. def __initDbClient(self):
  30. """
  31. init DB Client
  32. :return:
  33. """
  34. __type = None
  35. if "SSDB" == self.config.db_type:
  36. __type = "SsdbClient"
  37. else:
  38. pass
  39. assert __type, 'type error, Not support DB type: {}'.format(self.config.db_type)
  40. self.client = getattr(__import__(__type), __type)(name=self.config.db_name,
  41. host=self.config.db_host,
  42. port=self.config.db_port)
  43. def get(self, **kwargs):
  44. return self.client.get(**kwargs)
  45. def put(self, value, **kwargs):
  46. return self.client.put(value, **kwargs)
  47. def pop(self, **kwargs):
  48. return self.client.pop(**kwargs)
  49. def changeTable(self, name):
  50. self.client.changeTable(name)
  51. if __name__ == "__main__":
  52. account = DbClient().pop()
  53. print(account)