| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #pragma once
- #include <list>
- #include <mutex>
- #include "hiredis/hiredis.h"
- #include <thread>
- class CRedis
- {
- public:
- CRedis() {}
- ~CRedis()
- {
- this->_connect = nullptr;
- this->_reply = nullptr;
- }
- bool connect(const char* host, int port, const char* password);
- bool set(const char* key, const char* value);
- bool set(const char* key, const char* value, int second);
- void push(const char* key, std::list<const char*> &values);
- void pull(const char* key, std::list<const char*> &values);
- const char* get(const char* key);
- // 发布
- bool publish(const char* channel, const char* value);
- // 订阅
- void subscribe(const char* channel);
- // 取消订阅
- bool unsubscribe(const char* channel);
- // 读取订阅数据
- void getReply();
- private:
- void __delKey(const char* key);
- private:
- redisContext* _connect;
- redisReply* _reply;
- std::mutex mut;
- };
|