当前位置:网站首页>Code example of hiredis
Code example of hiredis
2022-06-28 22:35:00 【I want to master C++】
redis The simplest example of sending and receiving data
/* 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 success " << 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;
}边栏推荐
- 00 後雲原生工程師:用 Zadig 為思創科技(廣州公交)研發開源節流
- Use of dynamic panels
- Nc1033 palindrome substring of small a (ring, interval DP)
- code review
- Jointly explore digital technology and information security, and the fourth China Russia Digital Forum was successfully held
- 以产业互联网的发展为开端,行业才能进入到一个全新的发展阶段
- Use of axurer9 master
- Zadig 面向开发者的自测联调子环境技术方案详解
- 项目管理到底管的是什么?
- 昨天晚上失眠
猜你喜欢

YAYA LIVE CTO 唐鸿斌:真正本地化,要让产品没有「产地」属性

穿越过后,她说多元宇宙真的存在

Deploy grafana to realize graphical monitoring

超级工厂里的生意图鉴

Linux安装mysql5.7(CentOS7.6) 教程

Linux Installation mysql5.7 (centos7.6) tutorial
Sample code of using redis to realize the like function

如何制作精美的图片

【selenium自动化过程中的api抓包】browsermobproxy的安装和配置

基于graph-linked embedding的多组学单细胞数据整合与调控推理
随机推荐
基于graph-linked embedding的多组学单细胞数据整合与调控推理
Use of dynamic panels
Oracle deleting archived logs and adding scheduled tasks
Zadig + 洞态 IAST:让安全溶于持续交付
C#/VB.NET 将PDF转为Excel
Windows mysql5.7 enable binlog log
重磅!CDA认证考试备考答疑上线
Advanced workplace | understand the "entry" of position advantages
Competition rules for the "network security" event of the secondary vocational group in the skills competition of Guangxi Vocational Colleges in 2022
Description détaillée du schéma technique du sous - environnement syntonique auto - test de Zadig pour les développeurs
torch. nn. Transformer import failed
Qt5.15中qsrand,srand随机数生成函数已弃用问题
QtCreator5.15.0源码编译全过程记录
In order to control the risks, how to choose a franchise company?
[SSH] login without password
How to make beautiful pictures
Use of axurer9 master
What is the prospect of VR panoramic production?
数据可视化中柱状图的实例应用,让乘风破浪公演结果一目了然
台式机没声音怎么样才能解决