码农知识堂 - 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. }

  • 相关阅读:
    不知道如何将文字转语音?不如跟着我一起来操作
    Reggie外卖项目 —— 移动端小程序之手机验证码登录
    c++中特殊的知识点(持续更新)
    数据结构学习笔记 6-1 手撕AVL树 与 LeetCode真题(Java)
    传奇架设gom引擎常见问题
    问题及解决方案汇总
    InfoNCE Loss公式及源码理解
    【Python自然语言处理】使用SVM、随机森林法、梯度法等多种方法对病人罹患癌症预测实战(超详细 附源码)
    Java基础:Stream流和方法引用
    java基于ssm的快递物流管理系统
  • 原文地址:https://blog.csdn.net/Edidaughter/article/details/125480010
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号