redis的哈希的存取
redis 收发数据最简单的例子
适配器
typedef struct redisReply {
int type;
long long integer;
double dval;
size_t len;
char *str;
char vtype[4];
size_t elements;
struct redisReply **element;
} redisReply;
void *writeInfoToRedis(const SessionInfo &info)
{
redisContext *context;
redisReply *reply;
struct timeval timeout = {1, 500000};
context = redisConnectWithTimeout("127.0.0.1", 6379, timeout);
if (context == NULL || context->err)
{
if (context == NULL)
{
cout << "line = 604, Connection error == " << context->errstr << ", context->err = " << context->err << endl;
redisFree(context);
}
else
{
TRACE_LOG(EM_LEVEL_ERR, "Connection error: can't allocate redis contextn");
}
return NULL;
}
cout << "Connection 成功 " << endl;
reply = (redisReply *)redisCommand(context, "AUTH z4afort");
if (reply->type == REDIS_REPLY_ERROR)
{
cout << "[Redis] Auth failed" << endl;
redisFree(context);
freeReplyObject(reply);
return NULL;
}
string ssoSessionId = "11111111112";
string accNoFlag = "accno";
string accNo = "admin";
string phonenum = "15490878888";
string requestTime = "2022-03-25 16:27:41";
char arrAccNoFlag[20] = "accno";
char arrAccNo[20] = "admin";
reply = (redisReply *)redisCommand(context, "hset %s %b %b", ssoSessionId.c_str(), accNoFlag.data(),accNoFlag.length(),accNo.data(),accNo.length());
if (NULL == reply)
{
cout << "[ Redis] hset ssoSessionId failed,reply->str =" << reply->str << ",reply->type = " << reply->type << endl;
}
else
{
cout << "[ Redis] hset ssoSessionId succedd " << endl;
}
redisFree(context);
freeReplyObject(reply);
return NULL;
}



