码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • hiredis的代码示例


    redis的哈希的存取

    redis 收发数据最简单的例子

    适配器 

    1. /* This is the reply object returned by redisCommand() */
    2. typedef struct redisReply {
    3. int type; /* REDIS_REPLY_* */
    4. long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
    5. double dval; /* The double when type is REDIS_REPLY_DOUBLE */
    6. size_t len; /* Length of string */
    7. char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
    8. and REDIS_REPLY_DOUBLE (in additionl to dval). */
    9. char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null
    10. terminated 3 character content type, such as "txt". */
    11. size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
    12. struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
    13. } redisReply;

    1. void *writeInfoToRedis(const SessionInfo &info)
    2. {
    3. redisContext *context;
    4. redisReply *reply;
    5. struct timeval timeout = {1, 500000};
    6. context = redisConnectWithTimeout("127.0.0.1", 6379, timeout);
    7. if (context == NULL || context->err)
    8. {
    9. if (context == NULL)
    10. {
    11. cout << "line = 604, Connection error == " << context->errstr << ", context->err = " << context->err << endl;
    12. redisFree(context);
    13. }
    14. else
    15. {
    16. TRACE_LOG(EM_LEVEL_ERR, "Connection error: can't allocate redis context\n");
    17. }
    18. return NULL;
    19. }
    20. cout << "Connection 成功 " << endl;
    21. reply = (redisReply *)redisCommand(context, "AUTH z4afort");
    22. if (reply->type == REDIS_REPLY_ERROR)
    23. {
    24. cout << "[Redis] Auth failed" << endl;
    25. redisFree(context);
    26. freeReplyObject(reply);
    27. return NULL;
    28. }
    29. string ssoSessionId = "11111111112";
    30. string accNoFlag = "accno";
    31. string accNo = "admin";
    32. string phonenum = "15490878888";
    33. string requestTime = "2022-03-25 16:27:41";
    34. char arrAccNoFlag[20] = "accno";
    35. char arrAccNo[20] = "admin";
    36. reply = (redisReply *)redisCommand(context, "hset %s %b %b", ssoSessionId.c_str(), accNoFlag.data(),accNoFlag.length(),accNo.data(),accNo.length());
    37. if (NULL == reply)
    38. {
    39. cout << "[ Redis] hset ssoSessionId failed,reply->str =" << reply->str << ",reply->type = " << reply->type << endl;
    40. }
    41. else
    42. {
    43. cout << "[ Redis] hset ssoSessionId succedd " << endl;
    44. }
    45. redisFree(context);
    46. freeReplyObject(reply);
    47. return NULL;
    48. }

  • 相关阅读:
    docker学习笔记
    一步一步教你安装部署 Jenkins,不信你安不上
    2023年智慧政务一网通办云平台顶层设计与建设方案PPT
    第八节:类和对象【二】【this引用和包】
    【新品发布】洛微科技全新工业级高性能 D系列 TOF相机D3重磅上线!
    面试: Hashtable vs ConcurrentHashMap
    计算机毕业设计Java民宿短租交易平台(源代码+数据库+系统+lw文档)
    Cauchy distribution
    pyqt5:openpyxl 读取 Excel文件,显示在 QTableWidget 中
    Jenkins构建 Maven项目(微服务)并自动发布
  • 原文地址:https://blog.csdn.net/Edidaughter/article/details/125480010
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号