redis-server-wrapper
Type-safe Rust wrapper for redis-server and redis-cli with builder pattern APIs.
Manage Redis server processes for testing, development, and CI without Docker --
just redis-server and redis-cli on PATH.
Features
- Single server -- start/stop with builder pattern, auto-cleanup on drop
- Cluster -- spin up N-master clusters with optional replicas
- Sentinel -- full sentinel topology (master + replicas + sentinels)
- Custom binaries -- point to any
redis-server/redis-clipath - Arbitrary config -- pass any Redis directive via
.extra(key, value)
Prerequisites
redis-server and redis-cli must be available on your PATH (or specify custom paths).
Usage
The API is async-first and requires tokio. Enable the blocking feature
for synchronous wrappers; see the Blocking API section below.
Single Server
use RedisServer;
let server = new
.port
.bind
.start
.await
.unwrap;
assert!;
// Stopped automatically on drop.
Cluster
use RedisCluster;
let cluster = builder
.masters
.replicas_per_master
.base_port
.start
.await
.unwrap;
assert!;
Sentinel
use RedisSentinel;
let sentinel = builder
.master_port
.replicas
.sentinels
.start
.await
.unwrap;
assert!;
Blocking API
Enable the blocking feature for synchronous wrappers that require no async runtime:
[]
= { = "...", = ["blocking"] }
The blocking module mirrors the async API. Every operation blocks the calling thread
until it completes:
use RedisServer;
let server = new
.port
.bind
.start
.unwrap;
assert!;
// Stopped automatically on drop.
Cluster and Sentinel work the same way:
use ;
let cluster = builder
.masters
.base_port
.start
.unwrap;
assert!;
let sentinel = builder
.master_port
.replicas
.sentinels
.start
.unwrap;
assert!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.