zoukankan      html  css  js  c++  java
  • Sword redis C语言接口介绍

    hiredis安装
    hiredis是redis官方推荐的基于C接口的客户端组件,它提供接口,供c语言调用以操作数据库。
    在redis的源码包的deps/hiredis下就有它的源码
    安装方法,进入deps/hiredis目录,执行命令:
    make
    make install
    主要函数接口
        
    函数原型:redisContext *redisConnect(const char *ip, int port);
    说明:该函数用来连接redis数据库,参数为数据库的ip地址和端口,通常默认端口为6379。该函数返回一个redisContext对象。
    
    函数原型:void *redisCommand(redisContext *c, const char *format, …);
    说明:该函数执行redis命令,当然也包括由lua脚本组成的命令,返回redisReply对象。
    
    函数原型void freeReplyObject(void *reply);
    说明:释放redisCommand执行后返回的redisReply所占用的内存。
    
    函数原型:void redisFree(redisContext *c);
    说明:释放redisConnect()所产生的连接。
    //redisReply对象
    typedef struct redisReply {
         int type;                       // 返回结果类型
         long long integer;              // 返回类型为整型的时候的返回值
         size_t len;                     // 字符串长度
         char *str;                      // 返回错误类型或者字符类型的字符串 
         size_t elements;                // 返回数组类型时,元素的数量
         struct redisReply **element;    // 元素结果集合,redisReply对象 
     } redisReply;
    //返回结果类型
    REDIS_REPLY_STRING 1   //字符串
    REDIS_REPLY_ARRAY 2    //数组,多个reply,通过element数组以及elements数组大小访问
    REDIS_REPLY_INTEGER 3  //整型
    REDIS_REPLY_NIL 4      //空,没有数据
    REDIS_REPLY_STATUS 5   //状态,str字符串以及len
    REDIS_REPLY_ERROR 6    //错误,同STATUS
  • 相关阅读:
    spring-data-jpa 二、多对一结构、Repository
    bootstrap学习(二)页面
    bootstrap学习(一)栅格、布局
    ArrayList源码学习
    python学习-Pillow图像处理
    python学习-抓取知乎图片
    python-os创建文件夹-create_dir_if_not_exist.py
    python-shutil学习
    python-argparse批量修改后缀名-batch_file_rename.py
    python-argparse使用
  • 原文地址:https://www.cnblogs.com/zhanggaofeng/p/9866082.html
Copyright © 2011-2022 走看看