c/c++ client that supports redis-cluster?

2,168 views
Skip to first unread message

Ian P. Cooke

unread,
Jun 10, 2014, 4:28:45 PM6/10/14
to redi...@googlegroups.com
Is there a C or C++ client library that supports redis-cluster?  This issue implies that hiredis won't support redis-cluster.  I found this OpenSIPS module that rolled a partial implementation on its own.  I didn't find a C or C++ project similar to redis-rb-cluster... is there one?

-ipc

Дмитрий Шинкевич

unread,
Apr 2, 2015, 2:45:05 AM4/2/15
to redi...@googlegroups.com
you can try this c++ wrapper https://github.com/shinberg/cpp-hiredis-cluster for hired is with cluster support

среда, 11 июня 2014 г., 0:28:45 UTC+4 пользователь Ian P. Cooke написал:

Sam Fang

unread,
Apr 2, 2015, 3:45:30 AM4/2/15
to redi...@googlegroups.com
You may check this out, a C++ client for redis supporting redis cluster: http://luca3m.me/2014/04/02/redis3m.html

ShuXin Zheng

unread,
Apr 2, 2015, 10:44:27 AM4/2/15
to redi...@googlegroups.com
A redis library supporting all redis commands, including the redis cluster, see https://github.com/zhengshuxin/acl/tree/master/lib_acl_cpp/samples/redis
-zsx

在 2014年6月11日星期三 UTC+8上午4:28:45,Ian P. Cooke写道:

Senthil Nathan

unread,
Apr 11, 2015, 8:41:09 AM4/11/15
to redi...@googlegroups.com
Hi,
As noted in the post made by ipc below, there is a nice hiredis-cluster wrapper API built by Dmitrii Shinkevich. It became available in the second week of April/2015 (a few days after the Redis 3 release). It is simply a set of include files you have to use on top of hiredis 0.12 or higher versions. I tried it to port my single Redis instance based C/C++ application code to work with the new Redis 3 cluster. Dmitrii's hiredis-cluster wrapper works great.

You can get it from here: https://github.com/shinberg/cpp-hiredis-cluster

Good Luck.

Dmitrii Shinkevich

unread,
Apr 13, 2015, 8:49:52 AM4/13/15
to redi...@googlegroups.com
Thank you, Senthil Nathan.

i'll be glad to answer any questions.

This library is focused on very easy migrating from existing c++ source code that is already using hiredis library.

суббота, 11 апреля 2015 г., 16:41:09 UTC+4 пользователь Senthil Nathan написал:

ShuXin Zheng

unread,
Apr 14, 2015, 9:19:01 AM4/14/15
to redi...@googlegroups.com
The C++ redis client based on acl is easy to use, which supports cluster redis and single redis in multi-threads envirenment. Below is a simple exmple:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <vector>
#include "acl_cpp/lib_acl.hpp"

static int __max_conns = 100;

static void test_redis_string(acl::redis& cmd, const char* key)
{
    acl::string val("test_value");

    // call redis-server: SET key value
    if (cmd.set(key, val.c_str()) == false)
    {
        printf("redis set error: %s\r\n", cmd.result_error());
        return;
    }

    // clear the string buf space
    val.clear();

    // call redis-server: GET key
    if (cmd.get(key, val) == false)
        printf("get key error: %s\r\n", cmd.result_error());
}

static void test_redis_hash(acl::redis& cmd, const char* key)
{
    std::map<acl::string, acl::string> fields;

    fields["name1"] = "value1";
    fields["name2"] = "value2";
    fields["name3"] = "value3";

    // HMSET key field value ...
    if (cmd.hmset(key, fileds) == false)
    {
        printf("hmset failed: %s\r\n", cmd.result_error());
        return;
    }

    const char* names[] = { "name1", "name2", "name3" };
    size_t argc = 3;
    std::vector<acl::string> values;

    // HMGET key filed ...
    if (cmd.hmget(key, names, argc, &values) == false)
    {
        printf("hmget failed: %s\r\n", cmd.result_error());
        return;
    }

    printf("%s: %s, %s: %s, %s: %s\r\n",
        names[0], values[0].c_str(),
        names[1], values[1].c_str(),
        names[2], values[2].c_str());
}

static void test_redis_key(acl::redis& cmd, const char* key)
{
    if (cmd.exists(key) == false)
        printf("key not exists\r\n");
    else
        printf("key exists\r\n");
}

// run in one thread
static void* thread_main(void* arg)
{
    acl::redis_client_cluster* cluster = (acl::redis_client_cluster*) arg;

    acl::redis cmd;
    cmd.set_cluster(cluster, __max_conns);
    const char* key;

    for (int i = 0; i < 100000; i++)
    {
        key = "string_key";
        test_redis_string(cmd, key);
        test_redis_key(cmd, key);

    key = "hash_key";
    test_redis_hash(cmd, key);
    test_redis_key(cmd, key);

        // reset the redis command to free some memory
        cmd.clear();
    }

    return NULL;
}

int main(void)
{
    const char* redis_addr = "127.0.0.1:6379";
    int conn_timeout = 10, rw_timeout = 10;

    // declare redis cluster ojbect
    acl::redis_client_cluster cluster;
    cluster.set(redis_addr, __max_conns);

    pthread_attr_t attr;
    pthread_attr_init(&attr);

    // create first thread
    pthread_t id1;
    pthread_create(&id1, &attr, thread_main, &cluster);

    // create second thread
    pthread_t id2;
    pthread_create(&id2, &attr, thread_main, &cluster);

    pthread_join(&id1, NULL);
    pthread_join(&id2, NULL);

    return 0;
}

zsx

在 2015年4月2日星期四 UTC+8下午10:44:27,ShuXin Zheng写道:

Alexandr Topilski

unread,
Apr 15, 2015, 9:01:43 AM4/15/15
to redi...@googlegroups.com
May be FastoRedis (c++ gui client, based on hiredis) will be interesting for you, now we support basic cluster implementation.

вторник, 10 июня 2014 г., 23:28:45 UTC+3 пользователь Ian P. Cooke написал:
Reply all
Reply to author
Forward
0 new messages