Hiredis-redis cplusplus--redis3M
2015-12-17 17:28
645 查看
1.下载:
C++版本的redis client下载链接:https://github.com/mrpi/redis-cplusplus-client
2.首先需要安装boost库,在linux下安装boost库过程如下:
2.1 boost库下载到官网:http://www.boost.org/,当前最新版本为1.51.0
2.2 安装命令:
官网介绍:http://www.boost.org/doc/libs/1_51_0/more/getting_started/unix-variants.html
Select your configuration options and invoke ./bootstrap.sh again without the --help option. Unless you have write permission in your system's /usr/local/ directory,
you'll probably want to at least use
to install somewhere else. Also, consider using the --show-libraries and --with-libraries=library-name-list options
to limit the long wait you'll experience if you build everything. Finally,
will leave Boost binaries in the lib/ subdirectory of your installation prefix. You will also find a copy of the Boost headers in the include/ subdirectory of the installation prefix, so you
can henceforth use that directory as an #include path in place of the Boost root directory.
所以,如果是有root权限,直接:
$ ./bootstrap.sh --prefix=/usr/local
$ ./b2 install
安装过程中可能提示:
安装过程中提示: patchlevel.h:没有那个文件或目录
则:sudo apt-get install python-dev
如果出现说: bzlib.h:没有那个文件或目录
则:sudo apt-get install libbz2-dev
然后重新调用$ ./b2 install,
视具体机器性能,编译可能需要十几分钟到半个小时不等。
至此,boost安装完毕!
3. C++ client客户端安装
正常make就可以了,不过可能出错:提示说找不到lboost_thread-mt,
修改Makefile文件用VIM打开Makefile文件,把“lboost_thread-mt” 改成
“lboost_thread”保存重新make。
然后./test_client运行,
void doTest()
{
//redis默认监听端口为6387 可以再配置文件中修改
redisContext* c = redisConnect("127.0.0.1", 6379);
if ( c->err)
{
redisFree(c);
printf("Connect to redisServer faile\n");
return ;
}
printf("Connect to redisServer Success\n");
const char* command1 = "set stest1 value1";
redisReply* r = (redisReply*)redisCommand(c, command1);
if( NULL == r)
{
printf("Execut command1 failure\n");
redisFree(c);
return;
}
if( !(r->type == REDIS_REPLY_STATUS && strcasecmp(r->str,"OK")==0))
{
printf("Failed to execute command[%s]\n",command1);
freeReplyObject(r);
redisFree(c);
return;
}
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", command1);
const char* command2 = "strlen stest1";
r = (redisReply*)redisCommand(c, command2);
if ( r->type != REDIS_REPLY_INTEGER)
{
printf("Failed to execute command[%s]\n",command2);
freeReplyObject(r);
redisFree(c);
return;
}
C++版本的redis client下载链接:https://github.com/mrpi/redis-cplusplus-client
2.首先需要安装boost库,在linux下安装boost库过程如下:
2.1 boost库下载到官网:http://www.boost.org/,当前最新版本为1.51.0
2.2 安装命令:
官网介绍:http://www.boost.org/doc/libs/1_51_0/more/getting_started/unix-variants.html
Select your configuration options and invoke ./bootstrap.sh again without the --help option. Unless you have write permission in your system's /usr/local/ directory,
you'll probably want to at least use
<strong>$</strong> ./bootstrap.sh <strong>--prefix=</strong><em>path</em>/<em>to</em>/<em>installation</em>/<em>prefix</em>
to install somewhere else. Also, consider using the --show-libraries and --with-libraries=library-name-list options
to limit the long wait you'll experience if you build everything. Finally,
<strong>$</strong> ./b2 install
will leave Boost binaries in the lib/ subdirectory of your installation prefix. You will also find a copy of the Boost headers in the include/ subdirectory of the installation prefix, so you
can henceforth use that directory as an #include path in place of the Boost root directory.
所以,如果是有root权限,直接:
$ ./bootstrap.sh --prefix=/usr/local
$ ./b2 install
安装过程中可能提示:
安装过程中提示: patchlevel.h:没有那个文件或目录
则:sudo apt-get install python-dev
如果出现说: bzlib.h:没有那个文件或目录
则:sudo apt-get install libbz2-dev
然后重新调用$ ./b2 install,
视具体机器性能,编译可能需要十几分钟到半个小时不等。
至此,boost安装完毕!
3. C++ client客户端安装
正常make就可以了,不过可能出错:提示说找不到lboost_thread-mt,
修改Makefile文件用VIM打开Makefile文件,把“lboost_thread-mt” 改成
“lboost_thread”保存重新make。
然后./test_client运行,
void doTest()
{
//redis默认监听端口为6387 可以再配置文件中修改
redisContext* c = redisConnect("127.0.0.1", 6379);
if ( c->err)
{
redisFree(c);
printf("Connect to redisServer faile\n");
return ;
}
printf("Connect to redisServer Success\n");
const char* command1 = "set stest1 value1";
redisReply* r = (redisReply*)redisCommand(c, command1);
if( NULL == r)
{
printf("Execut command1 failure\n");
redisFree(c);
return;
}
if( !(r->type == REDIS_REPLY_STATUS && strcasecmp(r->str,"OK")==0))
{
printf("Failed to execute command[%s]\n",command1);
freeReplyObject(r);
redisFree(c);
return;
}
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", command1);
const char* command2 = "strlen stest1";
r = (redisReply*)redisCommand(c, command2);
if ( r->type != REDIS_REPLY_INTEGER)
{
printf("Failed to execute command[%s]\n",command2);
freeReplyObject(r);
redisFree(c);
return;
}
相关文章推荐
- redis 学习手册之发布和订阅pubsub操作
- redis 学习手册之键key操作
- Redis持久化
- CentOS 6.5安装Redis-2.8.23
- redis-backgroud saving error
- Redis面向java的Client
- redis初探
- 使用redis解决tomcat6在nginx负载下多节点共享session问题
- redis入门
- Redis基本配置
- Redis入门之redis 连接以及 对字符的操作
- redis cluster 添加 删除 重分配 节点
- Redis入门之Redis 安装超详细文档
- redis sentinel 主从切换(failover)解决方案,详细配置
- Reid主从复制简介
- keepalived实现redis双主备份
- Redis监控软件Redis-stat
- Redis的常用命令及高级应用
- redis主从
- redis集群