smulkutk
smulkutk

Reputation: 81

Does 'hiredis' support Redis Sentinel and Redis Cluster?

'hiredis' is a minimalistic C client for Redis. Does anyone know if it supports -

It is not clear from its Github page - https://github.com/redis/hiredis

Upvotes: 1

Views: 2643

Answers (1)

for_stack
for_stack

Reputation: 23041

YES and NO.

Since you can send any command to Redis with hiredis, you can get master/slave info from Redis Sentinel, or get the slots info from Redis Cluster. So hiredis can work with Redis Sentinel and Redis Cluster.

However, since hiredis doesn't have high level API to work with sentinel and cluster, you have to do many work by yourself. If you need high level API, you need to try other libraries, for example:

If you're coding with C, you can try hiredis-vip, which supports Redis Cluster. But I'm not sure if it supports Redis Sentinel.

If you're coding with C++, you can try redis-plus-plus, which supports both Redis Cluster and Redis Sentinel, and has STL-like interfaces.

Declaimer: I'm the author of redis-plus-plus.

// Example on redis-plus-plus

#include <sw/redis++/redis++.h>

try {
    auto cluster = RedisCluster("tcp://127.0.0.1:7000");
    cluster.set("key", "val");
    auto val = cluster.get("key");
    if (val) cout << *val << endl;
} catch (const Error &e) {
    cerr << e.what() << endl;
}

Upvotes: 2

Related Questions