当前位置:网站首页>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;
}边栏推荐
- TCP三次握手四次挥手
- 6年心得,从功能测试到测试开发,送给在测试路上一路走到黑的你
- 题解 洛谷P1762 偶数/6.21校内考试T2
- Redis+aop+ user defined annotation to realize flow restriction
- Zadig + sonarqube, ensuring the safety of the development process
- 职场进阶 | 了解岗位优势三板斧之“进场”
- Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
- Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
- Sample code of using redis to realize the like function
- Nc1033 palindrome substring of small a (ring, interval DP)
猜你喜欢

6年心得,从功能测试到测试开发,送给在测试路上一路走到黑的你

Rosdep update using fishros to solve ros1/ros2 problems 2022

Icon fill color and background color change together

项目管理到底管的是什么?

Ansible production environment usage scenario (7): batch deployment of elk clients

Analysis of CSRF Cross Site Request Forgery vulnerability

Interpretation of papers (DCN) towards k-means-friendly spaces: simultaneous deep learning and clustering

宜明昂科在港交所递表:2021年亏损翻倍,过往融资额存在夸大情形

Post-00 cloud native Engineer: use Zadig to increase revenue and reduce expenditure for the R & D of Sichuang Technology (Guangzhou public transport)

穿越过后,她说多元宇宙真的存在
随机推荐
Oracle删除归档日志及添加定时任务
Sample code of using redis to realize the like function
apipost脚本使用讲解一~全局变量
Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
IC Nansha|AMD高级副总裁、大中华区总裁潘晓明:制程、架构、平台优化突破计算边界
C#/VB.NET 将PDF转为Excel
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
In the era of industrial Internet, the Internet in the traditional sense will evolve into many new forms
【Try to Hack】nmap
Appium automated test Jiugongge unlock
GO语言-反射reflect
Quartz定时任务触发器启动时设置
How powerful is the Zadig build? Practice together
Move the mouse out of the selected area style cancel
嵌入式中 动态阿拉伯语字符串 转换 LCD显示字符串【感谢建国雄心】
Yiming Anke submitted a statement to the Hong Kong Stock Exchange: the loss doubled in 2021, and the past financing amount was exaggerated
Adding a markdown editor to lavel
[SSH] login without password
加刚干的前提
常用工具类与commons 类库