• 一例C语言凭借hiredis连接redis


    #include <stdio.h>
    #include <hiredis/hiredis.h>
    int main()
    {
        redisContext *c = redisConnect("127.0.0.1", 6379);
        if (c == NULL || c->err) {
            if (c) {
                printf("Error: %s
    ", c->errstr);
                // handle error
            } else {
                printf("Can't allocate redis context
    ");
            }
        }
        redisReply *reply=NULL;
        // set
        reply = redisCommand(c, "set %s %s", "name", "程劲");
        printf("set is %s
    ", reply->str);
        freeReplyObject(reply);
    
            // get
        reply = redisCommand(c, "get name");
        printf("name :%s
    ", reply->str);
        freeReplyObject(reply);
        printf("Hello World!
    ");
        return 0;
    }

    运行结果:

    前提:在github上找到 hiredis库,下载下来。在解压的文件中运行 make  make install 完成libhireids.so的生成。

    作为85后,习惯了在windows系统中,下个exe文件,双击安装,然后就可以在visual studio名正言顺的按照,某一款数据库或平台系统官方文档提供的示范代码,根据业务需求开发,现如今移到linux上,在终端上运行命令安装扩展库,还真是大开眼界

    时下更流行的做法是某些平台或数据库的连接代码和API全都放在github上,既可以方便维护升级,也方便分享。不过总给人感觉很野路子,可能是我太保守了。这里使用了hiredis这一连接库,当然别忘了在Qt项目中,添加库libhiredis.so

  • 相关阅读:
    MySQL++:MySQL 复合索引、普通索引总结
    AutoCAD 二次开发之python(学习中)
    APScheduler 学习笔记
    pylint 定制化配置/使用 -待整理
    JDK和CGLIB动态代理区别
    Java 类加载过程
    判断字符串是否是数字类型
    Java 并发编程锁工具
    花式写挂
    WC2021 题目清单
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/14003209.html
Copyright © 2020-2023  润新知