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.3.0"
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 for explicit control over cluster mode, credentials, and TLS:
use UniversalBuilder;
// Force cluster mode with a single address
let client = new
.cluster
.build?;
// ACL authentication (Redis 6.0+)
let client = new
.username
.password
.build?;
// TLS (requires the tls-rustls or tls-native-tls feature)
let client = new
.tls
.build?;
Features
All TLS features use the same names as the underlying redis crate.
| Feature | Description |
|---|---|
tls-native-tls |
TLS via native-tls (OS certificate store) |
tls-rustls |
TLS via rustls (native OS certificate store) |
tls-rustls-insecure |
rustls with support for TlsMode::Insecure (skips certificate verification) |
tls-rustls-webpki-roots |
rustls with Mozilla's WebPKI root certificates instead of the OS store |
tokio-native-tls-comp |
Alias for tls-native-tls |
tokio-rustls-comp |
Alias for tls-rustls |
TLS can also be enabled without these features by using a rediss:// URL directly:
[]
= { = "0.3.0", = ["tls-rustls"] }
// rediss:// enables TLS (secure); rediss://<host>/#insecure skips cert verification
let client = open?;
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 ACL authentication (requires Docker)
# Integration tests with Redis Cluster (requires Docker)
RUN_CLUSTER_TESTS=1
License
BSD-3-Clause