1.介绍

hiredis:

一个c/c++的访问redis的api库

地址:https://github.com/redis/hiredis

pipeline方式:

redis中的pipeline方式,指的是把多次请求交互封装到一次完成,只交互一次,类似于多个请求“批处理”成一次交互

好处:

同样是多次请求,用pipeline方式比多次请求的总的延时低,交互次数少,

即低延迟,高吞吐。

2.代码

int pipeline_process(struct timeval access_timeout, std::vector<std::string> & pipeline_cmd, std::vector<std::string> &pipeline_resp, std::vector<bool> &pipeline_resp_status)
{
if (0 == redis_ctx) {return -1;}
redisSetTimeout(redis_ctx, access_timeout); for (int i = 0; i < pipeline_cmd.size();i++)
{
redisAppendCommand(redis_ctx, pipeline_cmd[i].c_str());
} for (int i = 0; i < pipeline_cmd.size();i++)
{
bool status = false;
std::string resp_str = "";
redisReply *reply = 0; if(redisGetReply(redis_ctx, (void **)&reply) == REDIS_OK
&& reply != NULL
&& reply->type == REDIS_REPLY_STRING)
{
status = true;
resp_str = reply->str;
}
//free
freeReplyObject(reply); pipeline_resp_status.push_back(status);
pipeline_resp.push_back(resp_str); }
return 0;
}

  

3.解释:

参数:

struct timeval access_timeout:访问的超时时间

std::vector<std::string> & pipeline_cmd:pipeline处理的多个请求命令字符串

std::vector<std::string> &pipeline_resp:pipeline处理的多个请求返回的字符串

std::vector<bool> &pipeline_resp_status:pipeline处理的多个请求返回的状态

使用hiredis实现pipeline方式访问的更多相关文章

  1. Linux实现https方式访问站点

    超文本传送协议(HyperText Transfer Protocol,HTML)是一种通信协议,它允许将超文本标记语言文档从web服务器传送到wel浏览器. HTML的特点: 1.支持客户/服务器模 ...

  2. SharePoint—用REST方式访问列表

    REST的定义与作用 在SharePoint 2010中,基本上有如下几种数据访问方式: 服务器端对象模型 LINQ to SharePoint Web Service 客户端对象模型 ADO.NET ...

  3. salesforce 零基础学习(三十三)通过REST方式访问外部数据以及JAVA通过rest方式访问salesforce

    本篇参考Trail教程: https://developer.salesforce.com/trailhead/force_com_dev_intermediate/apex_integration_ ...

  4. 非链接方式访问数据库--查询的数据集用Dataset来存储。

    private void Button_Click_1(object sender, RoutedEventArgs e) { //非链接方式访问数据库, //1创建连接对象(连接字符串) using ...

  5. ADO.NET 连接方式和非链接方式访问数据库

    一.//连接方式访问数据库的主要步骤(利用DataReader对象实现数据库连接模式) 1.创建连接对象(连接字符串) SqlConnection con = new SqlConnection(Co ...

  6. httpclient 认证方式访问http api/resutful api并获取json结果

    最近,因公司线上环境rabbitmq经常发生堆积严重的现象,于是跟运维组讨论,帮助开发个集中监控所有rabbitmq服务器运行情况的应用,需要通过java访问rabbitmq暴露的http api并接 ...

  7. php 面向对象的方式访问数据库

    <body> <?php //面向对象的方式访问数据库 //造对象 $db = new MySQLi("localhost","root",& ...

  8. 以Lockbits的方式访问bitmap

    转载自:http://www.cnblogs.com/xiashengwang/p/4225848.html 2015-01-15 11:38 by xiashengwang, 585 阅读, 0 评 ...

  9. URL方式访问Hadoop的内容

    * 1.设置url支持hadoop,FsUrlStreamHandlerFactory      * 2.创建URL对象,指定访问的HDFS路径      * 3.openStream获取输入流对象, ...

随机推荐

  1. Codeforces Round #431 (Div. 1)

    A. From Y to Y time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. HDU 5242 Game(三个贪心)

    Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  3. Holding Bin-Laden Captive!(1.多重背包 2.母函数)

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  4. 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest A Email Aliases(模拟STL vector+map)

    Email AliasesCrawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     ...

  5. POJ 3468 A Simple Problem with Integers(树状数组区间更新) 续

    这个题刚开始的时候是套模板的,并没有真的理解什么树状数组的区间更新,这几天想了一下,下面是总结: 区间更新这里引进了一个数组delta数组,delta[i]表示区间 [i, n] 的共同增量,每次你需 ...

  6. SQL——按照季度,固定时间段,分组统计数据

    最近在工作中接到了一个需求,要求统计当月以10天为一个周期,每个周期的数据汇总信息.假设有一张表如下: 表table_test中 ID           AMOUNT         CREATE_ ...

  7. IdentityServer4实现Token认证登录以及权限控制

    相关知识点 不再对IdentityServer4做相关介绍,博客园上已经有人出了相关的系列文章,不了解的可以看一下: 蟋蟀大神的:小菜学习编程-IdentityServer4 晓晨Master:Ide ...

  8. AngularJS学习篇(十三)

    AngularJS HTML DOM ng-disabled 指令 ng-disabled 指令直接绑定应用程序数据到 HTML 的 disabled 属性. <!DOCTYPE html> ...

  9. mac下安装HTMLTestRunner

    HTMLTestRunner是Python标准库unittest模块的一个扩展.它生成易于使用的HTML测试报告. 1.下载HTMLTestRunner.py模块地址 http://tungwaiyi ...

  10. The Lisp Curse /Lisp魔咒

    The Lisp Curse /Lisp魔咒 http://winestockwebdesign.com/Essays/Lisp_Curse.html 英文出处 http://www.soimort. ...