1、linux下如何安装hiredis
1)下载地址
 https://github.com/redis/hiredis
2)编译和安装
解压后的文件夹执行 make;make install;
3)头文件包含
include <hiredis/hiredis.h>
4)编译选项
makefile文件中加入    LDFLAGS = -lhiredis
2、主要结构
主要关注2个结构体,
1)redisContext

  1. /* Context for a connection to Redis */
  2. typedef struct redisContext {
  3. int err; /* Error flags, 0 when there is no error */
  4. char errstr[128]; /* String representation of error when applicable */
  5. int fd;
  6. int flags;
  7. char *obuf; /* Write buffer */
  8. redisReader *reader; /* Protocol reader */
  9. enum redisConnectionType connection_type;
  10. struct timeval *timeout;
  11. struct {
  12. char *host;
  13. char *source_addr;
  14. int port;
  15. } tcp;
  16. struct {
  17. char *path;
  18. } unix_sock;
  19. } redisContext;

2)redisReply

  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. int len; /* Length of string */
  6. char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
  7. size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
  8. struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
  9. } redisReply;

2、主要接口
主要有4个接口,
1)redisContext* redisConnect(const char *ip, int port)
   //连接redis。
2)void *redisCommand(redisContext *c, const char *format, ...);
   //执行redis操作命令
3)void freeReplyObject(void *reply);
   //释放执行redis操作命令回复的内存
4)void redisFree(redisContext *c);

//释放连接上下文。

3、异常处理
主要4种异常情况会出现,
1)获得的redisContext指针为null
   异常处理办法:再次尝试与redis建立新的连接上下文。
2)获得的redisContext指针err不为0
   异常处理办法:再次尝试与redis建立新的连接上下文。
3)获得的redisReply指针为null
   异常处理办法:断开redis连接再次与redis建立连接并尝试执行命令。
4)获得的reply指针的type不是期望的类型,
   异常处理办法:断开redis连接再次与redis建立连接并尝试执行命令。
至此hiredis了解完毕,接下来就可以在其他模块中调用了。

hiredis 使用 linux c++的更多相关文章

  1. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

  2. Linux 下的hiredis的简单安装、测试*(转)

    上一章介绍的是如何安装Redis以及在Redis客户端上进行简单测试,但是我们一般安装完Redis之后,都是要结合编程语言对其进行应用的,hiredis是redis开源库对外发布的客户端API包,这一 ...

  3. redis3.0.6安装(linux和windows)

    官网上描述安装方法如下:$ wget http://download.redis.io/releases/redis-3.0.6.tar.gz$ tar xzf redis-3.0.6.tar.gz$ ...

  4. Redis介绍——Linux环境Redis安装全过程和遇到的问题及解决方案

    一:redis的入门介绍: 首先贴出官网; 英文:https://redis.io/ 中文:http://www.redis.cn/ 1.是什么 --REmote DIctionary Server( ...

  5. redis C接口hiredis 简单函数使用介绍

    hiredis是redis数据库的C接口,目前只能在linux下使用,几个基本的函数就可以操作redis数据库了. 函数原型:redisContext *redisConnect(const char ...

  6. linux系统下安装单台Redis

    注意:搭建redis前一定要安装gcc redis安装方式一 1.安装gcc命令:yum install -y gcc #安装gcc [root@localhost src]# yum install ...

  7. hiredis异步接口封装并导出到Lua

    hiredis异步接口封装并导出到Lua(金庆的专栏 2017.1)hiredis 不支持 Windows, Windows 下使用 wasppdotorg / hiredis-for-windows ...

  8. hiredis的各种windows版本

    hiredis的各种windows版本(金庆的专栏 2016.12)hiredis 是内存数据库 redis 的客户端C库, 不支持Windows.hiredis的Windows移植版本有许多:des ...

  9. Redis~Linux环境下的部署

    回到目录 Redis的生产环境建议部署到linux上,而在开发时可以连接windows版本,下面介绍如何在linux上部署redis. $ wget http://download.redis.io/ ...

随机推荐

  1. FormsAuthenticationTicket

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. 认识IQueryable和IQueryProvider接口

    1.Func<Student, bool>和Expression<Func<Student, bool>>的区别 class Program { static vo ...

  3. Git 从 master 分支拉新分支开发

    一. 切换到被copy的分支(master),并且从远端拉取最新版本 $git checkout master $git pull 二.从当前分支拉copy开发分支 $git checkout -b ...

  4. linux inotify 文件变化检测

    用webstorm开发angular项目的时候,改写文件后发现热更新有时候会失效,从而不得不重新运行下项目,然而这浪费了好多时间,google一番后,解决办法如下 echo fs.inotify.ma ...

  5. Java 之 Web前端(五)

    1.过滤器 a.定义:是一个中间组件,用于拦截源数据和目的数据之间的消息,并过滤二者之间传递的数据 b.步骤: ①建class继承Filter实现抽象方法 public class EncodingF ...

  6. 超越halcon速度的二值图像的腐蚀和膨胀,实现目前最快的半径相关类算法(附核心源码)。

    我在两年前的博客里曾经写过 SSE图像算法优化系列七:基于SSE实现的极速的矩形核腐蚀和膨胀(最大值和最小值)算法  一文,通过SSE的优化把矩形核心的腐蚀和膨胀做到了不仅和半径无关,而且速度也相当的 ...

  7. springboot整合springmvc上传文件

    1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...

  8. 在web项目中搭建一个spring mvc + spring + mybatis的环境

    介绍:本文中示范搭建一个ssm环境的框架:使用流程就是客户端通过http请求访问指定的接口,然后由服务器接受到请求处理完成后将结果返回. 本项目请求流程细节介绍:由客户端请求到指定的接口,这个接口是个 ...

  9. SpringBoot多数据源

    很多业务场景都需要使用到多数据库,本文介绍springboot对多数据源的使用. 这次先说一下application.properties文件,分别连接了2个数据库test和test1.完整代码如下: ...

  10. Vue初始

    一 .安装   https://cn.vuejs.org/ 官方网站 二 .简单实用示例 Vue.js 使用了基于 HTML 的模板语法,最简单的使用vue的方式是渲染数据,渲染数据最常见的形式就是使 ...