| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #pragma once
- #include <list>
- #include <mutex>
- #include <memory>
- #include "hiredis\hiredis.h"
- class CRedis
- {
- private:
- CRedis();
- CRedis(const CRedis&) = default;
- CRedis& operator=(const CRedis&) = default;
- public:
- ~CRedis();
- public:
- 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, const char* values);
- 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);
- static std::shared_ptr<CRedis> GetInstance() { return pInstance; }
- private:
- void __delKey(const char* key);
- bool __testCon();
- private:
- redisContext* _connect;
- redisReply* _reply;
- std::mutex mut;
- //char m_host[128];
- std::unique_ptr<char[]> m_pHost;
- int32_t m_port;
- //char m_pwd[128];
- std::unique_ptr<char[]> m_pPwd;
- std::int32_t m_isConnect; // ÊÇ·ñÁ¬½Ó
- static std::shared_ptr<CRedis> pInstance;
- };
|