【问题标题】:Does 'hiredis' support Redis Sentinel and Redis Cluster?“hiredis”是否支持 Redis Sentinel 和 Redis Cluster?
【发布时间】:2019-12-02 23:11:31
【问题描述】:

'hiredis' 是 Redis 的简约 C 客户端。有谁知道它是否支持-

从它的 Github 页面上不清楚 - https://github.com/redis/hiredis

【问题讨论】:

    标签: redis redis-sentinel hiredis redisclient


    【解决方案1】:

    是和否。

    由于您可以使用hiredis 向 Redis 发送任何命令,因此您可以从 Redis Sentinel 获取主/从信息,或从 Redis Cluster 获取插槽信息。所以hiredis 可以与 Redis Sentinel 和 Redis Cluster 一起使用。

    但是,由于hiredis 没有高级 API 来处理哨兵和集群,您必须自己做很多工作。如果需要高级API,需要尝试other libraries,例如:

    如果您使用 C 进行编码,您可以尝试支持 Redis 集群的 hiredis-vip。但我不确定它是否支持 Redis Sentinel。

    如果您使用C++ 进行编码,您可以尝试redis-plus-plus,它同时支持 Redis Cluster 和 Redis Sentinel,并具有类似 STL 的接口。

    声明者:我是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;
    }
    

    【讨论】:

    • 感谢@for_stack
    • hiredis-vip 不再维护。 hiredis-cluster 是一个积极维护的分支。它支持集群(不是哨兵)并使用hiredis作为依赖项。
    猜你喜欢
    • 1970-01-01
    • 2019-10-23
    • 2021-10-31
    • 2015-08-17
    • 1970-01-01
    • 2013-11-28
    • 2015-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多