您的位置:首页 > 数据库 > Redis

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
<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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: