xRedis API  1.5.0
The C++ Client API for Redis server
 All Classes
xRedis API Documentation

xRedis

Author
xSky

Redis C++ client, support the data slice storage, support the connection pool

Features:

Support multi-node distributed storage of data, can customize the sharding rules;
Support to connect to master and slave nodes of each shard at the same time, support separation of master and slave reads and writes;
Support connection pooling for each storage node;
Support simultaneous connection of multiple data sharding clusters;
Support for connecting to official clusters, single or multiple nodes Support to set up a connection pool to each node,
the client side automatically calculates the slot distribution;
Support automatic calculation of node index position;
Support Redis cluster node change connection automatic switch;
The connection pool to the cluster is automatically updated when the add/delete /slot distribution of the official cluster node changes.
Provide easy to use C++ interface encapsulation, has implemented most of the Redis command;
Only rely on the Hiredis library; Multi-thread safety Support password connection; Support Linux and Windows platforms

github

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

Dependencies

xRedis requires hiredis only

Install

First step install libhiredis, on a Debian/Ubuntu system you can use:

1 sudo apt-get install libhiredis-dev

on a Redhat/Centos system you can use:

1 sudo yum install hiredis-devel

Then checkout the code and compile it

1 git clone https://github.com/0xsky/xredis
2 cd xredis/src
3 make
4 sudo make install

Documentation

xRedis Architecture diagram
xRedis 架构图

example:

This is an example of how to use the xRedis.
This demo connect to single redis server with connection pool
More details about this example.

/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "xRedisClusterClient.h"
using namespace xrc;
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
xRedisClusterClient redisClusterClient;
std::string pass;
bool bRet = redisClusterClient.connect("127.0.0.1", 7001, pass, 4);
//bool bRet = redisClusterClient.ConnectRedis(argv[1], atoi(argv[2]), argv[3], 4);
if (!bRet) {
return -1;
}
RedisResult result;
redisClusterClient.command(result, "hgetall %s", "htest");
printf("type:%d integer:%lld str:%s \r\n", result.type(), result.integer(),
result.str());
for (size_t i = 0; i < result.elements(); ++i) {
RedisResult::RedisReply reply = result.element(i);
printf("type:%d integer:%lld str:%s \r\n", reply.type(), reply.integer(),
reply.str());
}
while (true) {
usleep(1000 * 1000 * 6);
redisClusterClient.keepalive();
}
return 0;
}

See examples directory for more examples
xRedis QQ Group: 190107312 xRedis��Դ����Ⱥ

Donate xRedis


Generated on Mon Mar 21 2022 10:57:13 for xRedis API version 1.5.0.