A Modern C++ Client for Redis

998 views
Skip to first unread message

sewe...@gmail.com

unread,
Apr 29, 2019, 11:24:56 PM4/29/19
to Redis DB
Hi all,

I wrote a C++ Redis client: redis-plus-plus. It's based on hiredis, and written in C++11. It supports all Redis features, e.g. Redis Cluster, Redis Sentinel, pub/sub, pipeline, transaction, scripting, and so on.

It has STL-like interface, and very easy to use.

auto redis = Redis("tcp://127.0.0.1:6379");
redis
.set("key", "val");
auto val = redis.get("key");
if (val) {
    cout
<< *val << endl;    // dereference to get the value of string type.
} // else key doesn't exist

redis
.rpush("list", {"a", "b", "c"});
vector
<string> vec;
redis
.lrange("list", 0, -1, std::back_inserter(vec));

Please check the doc for details.

This client is production ready, and fully tested with many compilers. If you have any problem, feel free to let me know.

Regards

Balaji J

unread,
May 10, 2019, 1:59:36 AM5/10/19
to Redis DB
Good to see the contribution and detailed documentation.

Can you pls clarify the following?
- Does this client support Async mode for every operation?
- Is there any way in the client to know about redis node failure event or new node addition(or removal) to cluster event etc?
- Any support available to identify the nearest redis slave incase of multi-dc scenario?

please clarify.

Thanks,
...Balaji.J

new sewe

unread,
May 10, 2019, 3:16:42 AM5/10/19
to Redis DB
Hi Balaji.J,

- Does this client support Async mode for every operation?

NO. By now, there's no async support, and there's a related open issue. If I have any progress on it, I'll let you know.

- Is there any way in the client to know about redis node failure event or new node addition(or removal) to cluster event etc?

redis-plus-plus will handle these cases automatically. If a standalone node is down, redis-plus-plus will try to reconnect to it. If you have deployed Redis Sentinel, and the master is down, redis-plus-plus will connect to the new master. In cluster mode, redis-plus-plus is able to handle the ASK & MOVED message properly, so that it can connect to the new node or forget connections to the removed node.

- Any support available to identify the nearest redis slave incase of multi-dc scenario?

NO. You have to manually create a connection to the nearest slave. With Sentinel support, redis-plus-plus will randomly pick a slave. I was thinking to support a ConnectionPolicy interface, so that the end user can customize how to select a slave. However, I still need to take a deep look at this idea, and haven't implemented it yet.

Regards

在 2019年5月10日星期五 UTC+8下午1:59:36,Balaji J写道:
Reply all
Reply to author
Forward
0 new messages