当前位置:网站首页>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;
}边栏推荐
- Zadig 面向开发者的自测联调子环境技术方案详解
- 2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fmt“ func main() {
- DBNN实验进展
- 如何结合均线分析伦敦金行情走势线图
- 【SSH】无密码登录
- Simple understanding of counting and sorting
- Deploy grafana to realize graphical monitoring
- Qtcreater5.15.0 source code compilation process record
- 软件测试的三个沟通技巧
- windows mysql5.7 开启binlog日志
猜你喜欢

Use of axurer9 option group

Steady! How thousands of micro services can quickly access Zadig (helm chart)

Zadig + 洞态 IAST:让安全溶于持续交付

After crossing, she said that the multiverse really exists

Gross vs60 billion. Is food safety the biggest obstacle to Weilong's listing?

Linux Installation mysql5.7 (centos7.6) tutorial

Architecture design of e-commerce secsha system

Move the mouse out of the selected area style cancel

QtCreator5.15.0源码编译全过程记录

这个简单的小功能,半年为我们产研团队省下213个小时
随机推荐
项目管理到底管的是什么?
Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)
穿越过后,她说多元宇宙真的存在
MSCI 2022年市场分类评估
Sample code of using redis to realize the like function
PyTorch搭建Transformer实现多变量多步长时间序列预测(负荷预测)
数据库基础笔记
【HackTheBox】 meow
职业问诊 | 在数据分析面试中,这样做自我介绍才靠谱
How to use London gold to draw support resistance line
Redis+AOP+自定义注解实现限流
Set when quartz scheduled task trigger starts
The new version of OpenAPI engine of Kingdee cloud dome is coming!
How to analyze the trend chart of London gold market with the moving average
Career consultation | in the data analysis interview, it is only reliable to introduce yourself in this way
Heavyweight! CDA certification test preparation Q & A Online
Analysis of CSRF Cross Site Request Forgery vulnerability
With the development of industrial Internet as the starting point, the industry can enter a new stage of development
Basic knowledge diagram of K-line Diagram -- meaning of single K-line
[kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box