DbClient.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. class DbClient(object):
  15. """
  16. DbClient
  17. """
  18. def __init__(self, db_type, name, host='localhost', port=8080, **kwargs):
  19. """
  20. init
  21. :param db_type: DB type
  22. :param name:
  23. :param host:
  24. :param port:
  25. :param kwargs:
  26. :return:
  27. """
  28. __type = None
  29. if "ssdb" in db_type.lower():
  30. __type = "SsdbClient"
  31. else:
  32. pass
  33. assert __type, 'type error, Not support DB type: {}'.format(db_type)
  34. self.client = getattr(__import__(__type), __type)(name=name, host=host, port=port, **kwargs)
  35. def get(self, **kwargs):
  36. return self.client.get(**kwargs)
  37. def put(self, **kwargs):
  38. return self.client.put(**kwargs)
  39. def pop(self, **kwargs):
  40. return self.client.pop(**kwargs)
  41. if __name__ == "__main__":
  42. account = DbClient('SSDB').pop()
  43. print(account)