hredis
https://www.csdn.net/gather_2f/MtTaEgwsMTUwLWJsb2cO0O0O.html
然後,就可以基於hiredis API開發客戶端了。可是hiredis不支持集羣。支持集羣的API:
C++ https://github.com/eyjian/r3c
C++ https://github.com/zhengshuxin/acl
https://github.com/zhengshuxin/acl/tree/master/lib_acl_cpp/samples/redis
C https://github.com/vipshop/hiredis-vip.git
hiredis-vip:
#include<stdio.h>
#include<hircluster.h>
int main()
{
redisClusterContext *cc = redisClusterConnect("127.0.0.1:7000,127.0.0.1:7001",HIRCLUSTER_FLAG_NULL);
if(cc == NULL || cc->err)
{
printf("connect error : %s\n", cc == NULL ? "NULL" : cc->errstr);
return -1;
}
int i;
redisReply* reply = NULL;
for(i=0; i<10000; i++)
{
//set
reply = redisClusterCommand(cc, "set key%d value%d", i, i);
if(reply == NULL)
{
printf("set key%d, reply is NULL, error info: %s\n", i, cc->errstr);
redisClusterFree(cc);
return -1;
}
printf("set key%d, reply:%s\n", i, reply->str);
freeReplyObject(reply);
//get
reply = redisClusterCommand(cc, "get key%d", i);
if(reply == NULL)
{
printf("get key%d, reply is NULL, error info: %s\n", i, cc->errstr);
redisClusterFree(cc);
return -1;
}
printf("get key%d, reply:%s\n", i, reply->str);
freeReplyObject(reply);
}
redisClusterFree(cc);
return 0;
}
RedisConnect
https://blog.csdn.net/xungen/article/details/90645981
分享一個開源的Redis連接庫RedisConnect,官方地址:https://www.winfengtech.com/redisconnect
介紹
1、RedisConnect是基於C++11實現的簡單易用的Redis客戶端。
2、源碼只包含一個頭文件與一個命令行工具源文件,無需編譯安裝,真正做到零依賴。
3、自帶連接池功能,調用Setup方法初始化連接池,然後執行Instance方法就可以獲取一個連接。
4、RedisConnect包裝了常用的redis命令,對於未包裝的命令你可以使用可變參模板方法(execute)進行調用。
安裝方法
1、下載源碼
git clone https://gitee.com/xungen/redisconnect.git