#ifndef REDISCLIENT #define REDISCLIENT #include #include #include #include #include #include #include #include using std::string; using std::cout; using std::endl; using namespace baosight; using namespace log4cplus; class RedisClient { public: ~RedisClient() { redisFree(mp_conn); //freeReplyObject(mp_reply); }; RedisClient() { LOG d("RedisClient()"); ConfigMag configmag("CRGS"); string server = configmag.ReadProperty("redis","server"); string passwd = configmag.ReadProperty("redis","passwd"); string port = configmag.ReadProperty("redis","port"); d.Info()<<"server:"<err){ if(mp_conn){ d.Error()<<"mp_connection error"<< mp_conn->errstr << endl; }else{ d.Error()<<"cannot alloc redis context"<str < 0) { freeReplyObject(mp_reply); redisCommand(mp_conn,"expire %s %d",key,expiretime); } string str = mp_reply->str; freeReplyObject(mp_reply); return str; } /**** *set redis data expire time *key:key *time: expire time[s] */ string expire(const char *key,int time) { // LOG d("RedisClient::expire"); if(key == NULL) { // d.Error() <<"key == NULL"<str; freeReplyObject(mp_reply); return str; } /**** *get redis value by key */ string get(const char *key) { // LOG d("RedisClient::get"); if(key == NULL){ // d.Error()<<"key = NULL"<len <= 0){ // d.Error()<<"no value"<str; freeReplyObject(mp_reply); return str; } private: redisContext *mp_conn; redisReply *mp_reply; }; #endif