12345678910111213141516171819202122232425262728293031323334353637 |
- #ifndef FROMREDIS_H
- #define FROMREDIS_H
- #include <string>
- #include "hiredis.h"
- class FromRedis
- {
- public:
- FromRedis();
- ~FromRedis();
- /* 设置IP和端口 */
- void setRedisIPAndPort(const std::string& ip, int port = 6379);
- /* 设置密码 */
- void setRedisPassword(const std::string& password);
- /* 连接Redis */
- bool connectRedis();
- /* 断开Redis连接 */
- void disConnectRedis();
- /* 获取redis中的string数据 */
- bool getRedisString(const std::string& key, std::string& value);
- private:
- /* 登录认证Redis,这个需要在连接成功后调用 */
- bool authRedis(const std::string& password);
- private:
- redisContext* m_redisContext = nullptr;
- std::string m_redisIP; /* Redis IP地址 */
- int m_redisPort; /* Redis默认端口 */
- std::string m_redisPassword; /* Redis密码 */
- };
- #endif /* FROMREDIS_H */
|