FromRedis.h 920 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef FROMREDIS_H
  2. #define FROMREDIS_H
  3. #include <string>
  4. #include "hiredis/hiredis.h"
  5. class FromRedis
  6. {
  7. public:
  8. FromRedis();
  9. ~FromRedis();
  10. /* 设置IP和端口 */
  11. void setRedisIPAndPort(const std::string& ip, int port = 6379);
  12. /* 设置密码 */
  13. void setRedisPassword(const std::string& password);
  14. /* 连接Redis */
  15. bool connectRedis();
  16. /* 断开Redis连接 */
  17. void disConnectRedis();
  18. /* 获取redis中的string数据 */
  19. bool getRedisString(const std::string& key, std::string& value);
  20. private:
  21. /* 登录认证Redis,这个需要在连接成功后调用 */
  22. bool authRedis(const std::string& password);
  23. private:
  24. redisContext* m_redisContext = nullptr;
  25. std::string m_redisIP; /* Redis IP地址 */
  26. int m_redisPort; /* Redis默认端口 */
  27. std::string m_redisPassword; /* Redis密码 */
  28. };
  29. #endif /* FROMREDIS_H */