xRedis 1.4 版本发布!支持Redis官方集群

2020-09-24 22:47:45

xRedis 1.4 版本发布!

xRedis 是一个 C++ 开发的 redis 客户端,是对 hiredis 的 C++ 封装,提供易用的 redis 命令操作接口。

功能与特点:

  • 支持数据多节点分布存储,可自定义分片规则;

  • 支持连接到官方集群,支持自动计算节点索引位置;

  • 支持同时连接到每个分片的主从节点,支持主从读写分离;

  • 支持对每个存储节点建立连接池;

  • 支持同时连接多个数据分片集群;

  • 提供简单易用的C++接口封装,已实现大部分REDIS命令;

  • 多线程安全; 

  • 只依赖hiredis库;

  • 支持官方集群访问。

release 1.4:

  1. 重构分片索引接口,提高易用性。

  2. xRedisClusterClient模块多个BUG修复。

  3. xRedisClusterClient功能更新。

访问 Redis官方集群示例

#include "xRedisClusterClient.h"
int main(int argc, char **argv) {
    xRedisClusterClient redisclient;
    # Connect to REDIS and establish a connection pool 
    # If this node is a member of the REDIS cluster, 
    # a connection pool is automatically established for each primary node in the cluster.
    std::string passwd = "passwd123";
    bool bRet = redisclient.connect("127.0.0.1", 6379, passwd, 4);

    RedisResult result;
    redisclient.command(result, "set %s %s", "key", "hello");
    
    printf("type:%d integer:%lld str:%s \r\n",
        result.type(), result.integer(), result.str());

   while (true) {
        usleep(1000*1000*6);
        redisclient.keepalive();
    }

    return 0;
}

 

更多内容见:

https://github.com/0xsky/xredis