linux版本中间件

CRedis.h 869B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include <list>
  3. #include <mutex>
  4. #include "hiredis/hiredis.h"
  5. #include <thread>
  6. class CRedis
  7. {
  8. public:
  9. CRedis() {}
  10. ~CRedis()
  11. {
  12. this->_connect = nullptr;
  13. this->_reply = nullptr;
  14. }
  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, std::list<const char*> &values);
  19. void pull(const char* key, std::list<const char*> &values);
  20. const char* get(const char* key);
  21. // 发布
  22. bool publish(const char* channel, const char* value);
  23. // 订阅
  24. void subscribe(const char* channel);
  25. // 取消订阅
  26. bool unsubscribe(const char* channel);
  27. // 读取订阅数据
  28. void getReply();
  29. private:
  30. void __delKey(const char* key);
  31. private:
  32. redisContext* _connect;
  33. redisReply* _reply;
  34. std::mutex mut;
  35. };