当前位置:网站首页>hiredis的代码示例
hiredis的代码示例
2022-06-28 22:17:00 【我要精通C++】
/* 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;
}边栏推荐
- Redis+aop+ user defined annotation to realize flow restriction
- 共探数字技术与信息安全,第四届中俄数字论坛成功举办
- Ansible production environment usage scenario (7): batch deployment of elk clients
- What does project management really manage?
- 职场人调研报告:裸辞占比最高的居然是中年人
- Summary of time series prediction series (code usage)
- Zadig + cave Iast: let safety dissolve in continuous delivery
- 【HackTheBox】dancing(SMB)
- apipost脚本使用讲解一~全局变量
- 基于graph-linked embedding的多组学单细胞数据整合与调控推理
猜你喜欢

爱数SMART 2022峰会开启,分享数据战略与建设数据驱动型组织方法论

k线图基础知识图解——单根K线的含义

Get to know Alibaba cloud (Cloud Computing) - development history, technical architecture, region and availability zone!

Zadig 面向開發者的自測聯調子環境技術方案詳解

Ingénieur natif du nuage après 00: utiliser Zadig pour développer des sources ouvertes et des économies d'énergie pour la technologie innovante (bus de Guangzhou)

After crossing, she said that the multiverse really exists

这个简单的小功能,半年为我们产研团队省下213个小时

Considerations on the construction of operation and maintenance system - stability

终于有人把云原生架构讲明白了

What is the prospect of VR panoramic production?
随机推荐
Career consultation | what should I answer when I am asked about my intended salary during the interview?
重磅!CDA认证考试备考答疑上线
Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering
How to make beautiful pictures
这个简单的小功能,半年为我们产研团队省下213个小时
Nc1033 palindrome substring of small a (ring, interval DP)
Can we still enter the "pit" data analysis now? Look at the hot jobs of data analysis in 2022!
5毛VS600亿,食品安全问题是卫龙上市最大的拦路虎?
How to advance data analysis from 1 to 10?
解读 | 数据分析的发展和演变都经过哪几个阶段?
Use of axurer9 option group
稳!上千微服务如何快速接入 Zadig(Helm Chart 篇)
穿越过后,她说多元宇宙真的存在
Oracle set password complexity and timeout exit function
Use of axurer9 master
面试官:Redis中字符串的内部实现方式是什么?
torch.nn.Transformer导入失败
Simple understanding of counting and sorting
数据库基础笔记
Gross vs60 billion. Is food safety the biggest obstacle to Weilong's listing?