中间件底层,websocket

CRedis.h 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include <list>
  3. #include <mutex>
  4. #include <memory>
  5. #include "hiredis\hiredis.h"
  6. class CRedis
  7. {
  8. private:
  9. CRedis();
  10. CRedis(const CRedis&) = default;
  11. CRedis& operator=(const CRedis&) = default;
  12. public:
  13. ~CRedis();
  14. public:
  15. bool connect(const char* host, int port, const char* password);
  16. bool set(const char* key, const char* value);
  17. bool set(const char* key, const char* value, int second);
  18. void push(const char* key, const char* values);
  19. void push(const char* key, std::list<const char*> &values);
  20. void pull(const char* key, std::list<const char*> &values);
  21. const char* get(const char* key);
  22. static std::shared_ptr<CRedis> GetInstance() { return pInstance; }
  23. private:
  24. void __delKey(const char* key);
  25. bool __testCon();
  26. private:
  27. redisContext* _connect;
  28. redisReply* _reply;
  29. std::mutex mut;
  30. //char m_host[128];
  31. std::unique_ptr<char[]> m_pHost;
  32. int32_t m_port;
  33. //char m_pwd[128];
  34. std::unique_ptr<char[]> m_pPwd;
  35. std::int32_t m_isConnect; // ÊÇ·ñÁ¬½Ó
  36. static std::shared_ptr<CRedis> pInstance;
  37. };