$ show sewenew/redis-plus-plus
redis-plus-plus is a production-grade C++ Redis client library built on hiredis, providing synchronous, asynchronous (libuv), and experimental coroutine (C++20) APIs. It covers the full Redis command surface including strings, hashes, lists, sets, sorted sets, streams, geospatial, hyperloglog, pub/sub, scripting, transactions, pipelines, and server commands. The architecture separates low-level connection management (connection pools, shard pools for clusters, sentinel discovery) from high-level facade classes (Redis, RedisCluster, AsyncRedis, AsyncRedisCluster, QueuedRedis for pipelined/transactional usage). Key entry points include the main sync header `redis++.h`, async header `async_redis++.h`, and coroutine header `co_redis++.h`. Data flows involve constructing Redis commands via `CmdArgs` and `cmd_formatter.h`, sending them through `Connection` objects (optionally pooled), and parsing replies with `reply.h`. The library depends on hiredis for raw Redis protocol, libuv for async I/O, and optionally Boost or OpenSSL for advanced features. It includes a comprehensive test suite covering all commands, multi-threading, cluster, sentinel, and distributed locking patterns (Redlock).
The LLM identified 5 files worth highlighting for reuse:
Provides a thread-safe, lazy-created `ConnectionPool` with configurable size, wait timeout, connection lifetime, and sentinel integration. The pool manages hiredis `redisContext` objects via RAII and supports role-based routing (master/slave). This component is self-contained, requiring only `Connection` and `Sentinel` abstractions, and can be reused in any C++ project needing a generic connection pool pattern.
Implements a libuv-based reactor (event loop) that serves as the core for all async operations. Manages connection watchers, periodic timers, and safe stop/start semantics. The `EventLoop` is a reusable async I/O dispatcher that could be extracted for any C++ project requiring an event-driven framework without coupling to Redis specifics.
Contains a complete implementation of the Redlock distributed lock algorithm and a higher-level `RedMutex` with automatic lock extension via `LockWatcher`. Uses Lua scripting or transactions to ensure atomicity. This is a self-contained pattern that can be extracted and reused for distributed coordination in any Redis-backed system.
Defines `CmdArgs`, a variadic template class that accumulates Redis command arguments from scalar values, iterator ranges, initializer lists, and output iterators. It handles type conversion and memory ownership through RAII. This utility is a clean example of C++ template metaprogramming for generic protocol argument construction and is reusable independently.
Provides a `Uri` class that parses Redis-specific connection URIs (tcp:// and unix://) with query parameters for authentication, database index, timeouts, and TLS. The parser is self-contained and could be reused in any C++ project needing URI-based configuration injection.