redis-universal-client
Simple wrapper around redis::Client and redis::cluster::ClusterClient, inspired by go-redis UniversalClient.
Provides a single UniversalClient type that works with both standalone Redis and Redis Cluster, using async multiplexed connections under the hood.
Usage
Add to your Cargo.toml:
[]
= "0.0.3"
Standalone Redis
use AsyncCommands;
use UniversalClient;
async
Redis Cluster
When multiple addresses are provided, open automatically creates a cluster client:
use AsyncCommands;
use UniversalClient;
async
Builder
Use UniversalBuilder to force cluster mode even with a single address:
use UniversalBuilder;
let client = new
.cluster
.build?;
How it works
| Addresses | open behavior |
UniversalBuilder behavior |
|---|---|---|
| 1 address | Client (standalone) |
Depends on .cluster() flag |
| N addresses | ClusterClient |
Depends on .cluster() flag |
UniversalConnection implements redis::aio::ConnectionLike, so you can use all redis::AsyncCommands on it. Both variants use async multiplexed connections (MultiplexedConnection / cluster_async::ClusterConnection) which are Clone + Send + Sync.
Testing
# Unit tests (no Docker required)
# Integration tests with standalone Redis (requires Docker)
# Integration tests with Redis Cluster (requires Docker)
RUN_CLUSTER_TESTS=1
License
BSD-3-Clause