Redis接口的调用
1、hiredis是redis数据库的C接口,目录为/redis-3.2.6/deps/hiredis
2、示例代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include "hiredis.h" int main()
{
//连接redis
redisContext* c = redisConnect("127.0.0.1", 6379);
if ( c->err)
{
redisFree(c);
printf("Connect to redisServer faile\n");
return -1;
}
printf("Connect to redisServer Success\n"); const char* setCommand = "set name andy";
redisReply* r = (redisReply*)redisCommand(c, setCommand); if( NULL == r)
{
printf("Execut setCommand failure\n");
redisFree(c);
return -1;
}
if( !(r->type == REDIS_REPLY_STATUS && strcasecmp(r->str,"OK")==0))
{
printf("Failed to execute command[%s]\n",setCommand);
freeReplyObject(r);
redisFree(c);
return -1;
}
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", setCommand); const char* getCommand = "get name";
r = (redisReply*)redisCommand(c, getCommand);
if ( r->type != REDIS_REPLY_STRING)
{
printf("Failed to execute command[%s]\n",getCommand);
freeReplyObject(r);
redisFree(c);
return -1;
}
printf("Succeed to execute command[%s]\n", getCommand);
printf("The value of 'name' is %s\n", r->str);
freeReplyObject(r); redisFree(c);
return 0;
}
3、编译,运行如下:
[root@localhost hiredis]# g++ -o main main.cpp libhiredis.a
[root@localhost hiredis]# ./main
Connect to redisServer Success
Succeed to execute command[set name andy]
Succeed to execute command[get name]
The value of 'name' is andy
Redis接口的调用的更多相关文章
- 基于AOP和Redis实现对接口调用情况的监控及IP限流
目录 需求描述 概要设计 代码实现 参考资料 需求描述 项目中有许多接口,现在我们需要实现一个功能对接口调用情况进行统计,主要功能如下: 需求一:实现对每个接口,每天的调用次数做记录: 需求二:如果某 ...
- 【转】java通用URL接口地址调用方式GET和POST方式
java通用URL接口地址调用方式GET和POST方式,包括建立请求和设置请求头部信息等等......... import java.io.ByteArrayOutputStream; import ...
- 如何让Java和C++接口互相调用:JNI使用指南
如何让Java和C++接口互相调用:JNI使用指南 转自:http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos ...
- 如何记录selenium自动化测试过程中接口的调用信息
上一篇博客,我写了python自动化框架的一些知识和粗浅的看法,在上一篇中我也给自己提出一个需求:如果记录在测试过程中接口的调用情况?提出这个需求,我觉得是有意义的.你在测试过程中肯定会遇到一些莫名其 ...
- 在Winform混合式框架中整合外部API接口的调用
在我们常规的业务处理中,一般内部处理的接口多数都是以数据库相关的,基于混合式开发的Winform开发框架,虽然在客户端调用的时候,一般选择也是基于Web API的调用,不过后端我们可能不仅仅是针对我们 ...
- ledisdb:支持类redis接口的嵌入式nosql
ledisdb现在可以支持嵌入式使用.你可以将其作为一个独立的lib(类似leveldb)直接嵌入到你自己的应用中去,而无需在启动单独的服务. ledisdb提供的API仍然类似redis接口.首先, ...
- 【Redis】安装 Redis接口时异常 ,系统ruby版本过低
场景 操作系统Linux CentOS 7.2,安装Redis接口时,使用命令:gem install redis ,用于系统ruby版本过低,报错“redis requires Ruby versi ...
- SAP接口的调用
最近做一个专案用到的SAO接口的调用,用到的上传参数获取回传的IRfcTable,以及以IRfcTable作为参数上传SAP,通过查阅很多资料,发现资料说明的也多是鱼龙混杂,许多没有实现就直接贴在上面 ...
- sso接口的调用
之前一直想sso接口已经写好了,登录注册功能是怎么调用的呢?原来在登录注册的jsp页面实现的接口的调用,页面的校验和验证功能在jsp页面即可实现. 注册页面: <%@ page language ...
随机推荐
- Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第五集之网络配置】
还有对第五集的补充:https://www.cnblogs.com/lirenhe/p/10405069.html 1,如果不为这个linux系统或者这台虚拟机配置IP,就不能实现通信.这样的之后安装 ...
- 自定义PDO封装类
<?php class Db { protected static $_instance = null; // 定义标识符(通过$_instance值得改变情况,来判定Model类是否被实例化) ...
- HDU 1435 Stable Match 【稳定婚姻问题】
<题目链接> 题目大意:给你n个发射站和n个接受站的位置,并且给出他们的容量,现在需要你对这n对站台进行匹配,距离越近的站台越稳定,如果两个站台距离相等,容量越大的越稳定.问你稳定匹配是什 ...
- c/c++关于指针的一点理解
#include <iostream> #include <string> using namespace std; int main() { }, n{}; cout < ...
- PostgreSQL 在Ubuntu下如何修改postgres默认密码
Step1: 切换用户为postgres sudo su postgres Step2: 用postgres连接postgreSQL psql -U postgres Step3: 修改postgre ...
- 笔记-JS高级程序设计-变量,作用域和内存问题
1在将一个值赋给变量时,解析器必须确认这个值是基本类值还是引用类型值,基本类型值是按值访问的,可以操作保存在在变量中的实际值,引用类型是保 存在内存中的对象,JS不允许直接访问内存中的位置,所以实际操 ...
- elf 学习
现在我们使用 readelf 命令来查看 elfDome.out 的文件头 readelf -l elfDemo.out 使用 readelf 来查看程序头: readelf -S elfDemo.o ...
- 表达式语言引擎:Apache Commons JEXL 2.1 发布
http://www.linuxde.net/2011/12/4348.html Commons JEXL 2.1 发布了,该版本和 2.0.1 是二进制兼容的,但源码不兼容,因为新增了两个接口: o ...
- continue — Skip to the next iteration of a loop in a shell script
continue — Skip to the next iteration of a loop in a shell script
- [OC] @property时,copy、strong、weak、assign的区别
@property(copy,nonatomic)NSMutableString*copyStr; @property(strong,nonatomic)NSMutableString*strongS ...