a8/a8/redis.h
2018-08-26 20:34:01 +08:00

42 lines
1.0 KiB
C++

#ifndef A8_REDIS_HPP
#define A8_REDIS_HPP
#include <hiredis.h>
namespace a8
{
class Redis
{
public:
Redis();
~Redis();
bool Connect(const std::string& host, int port, int timeout=10);
bool Ping();
std::tuple<bool, a8::XValue> HGet(const std::string& key, const std::string& field);
std::tuple<bool, a8::XValue> HSet(const std::string& key, const std::string& field, a8::XValue& val);
std::tuple<bool, a8::XValue> HDel(const std::string& key);
std::tuple<bool, a8::XValue> Get(const std::string& key);
std::tuple<bool, a8::XValue> Set(const std::string& key, a8::XValue& val);
std::tuple<bool, a8::XValue> Del(const std::string& key);
std::tuple<bool, a8::XValue> PExpire(const std::string& key, unsigned short mill_sec);
private:
std::tuple<bool, a8::XValue> ExecCommand(const std::string& command);
private:
redisContext* redis_ = nullptr;
std::string host_;
int port_ = 0;
int timeout_ = 0;
};
}
#endif