- /* This is the reply object returned by redisCommand() */
- typedef struct redisReply {
- int type; /* REDIS_REPLY_* */
- long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
- double dval; /* The double when type is REDIS_REPLY_DOUBLE */
- size_t len; /* Length of string */
- char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
- and REDIS_REPLY_DOUBLE (in additionl to dval). */
- char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null
- terminated 3 character content type, such as "txt". */
- size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
- struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
- } 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 context\n");
- }
- 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;
- }