redis-oxide
redis-oxide is an async Redis client for Rust. It provides topology detection,
Redis Cluster support, Sentinel support, connection pooling, RESP2/RESP3
protocol handling, Pub/Sub, Streams, Lua scripting, transactions, and pipelines.
The crate is designed for Tokio applications that need a practical Redis client with a typed API and predictable behavior across standalone and clustered Redis deployments.
Installation
[]
= "0.2.3"
= { = "1", = ["full"] }
Quick Start
use ;
async
Core Operations
use HashMap;
use Duration;
// Assume `client` is a connected redis_oxide::Client.
client.set.await?;
client.set_ex.await?;
let value: = client.get.await?;
let ttl: = client.ttl.await?;
client.hset.await?;
let fields: = client.hgetall.await?;
client.lpush.await?;
let jobs: = client.lrange.await?;
client.sadd.await?;
let tags = client.smembers.await?;
let mut scores = new;
scores.insert;
scores.insert;
client.zadd.await?;
ttl preserves Redis sentinel values. A missing key returns Some(-2) and a key
without expiration returns Some(-1).
Advanced Usage
Pipelines
let mut pipeline = client.pipeline;
pipeline.set;
pipeline.set;
pipeline.get;
let results = pipeline.execute.await?;
Redis server errors inside a pipeline are returned as per-command
RespValue::Error entries. Transport and connection failures still fail the
whole pipeline.
Transactions
let mut transaction = client.transaction.await?;
transaction.watch.await?;
transaction.get;
transaction.set;
let results = transaction.exec.await?;
Lua Scripts
use Script;
let script = new;
let result: String = script.execute.await?;
Script::execute tries EVALSHA first and falls back to EVAL when Redis
returns NOSCRIPT.
Pub/Sub
client.publish.await?;
let mut subscriber = client.subscriber.await?;
subscriber.subscribe.await?;
if let Some = subscriber.next_message.await?
Streams
use HashMap;
let mut fields = new;
fields.insert;
let id = client.xadd.await?;
let messages = client
.xread
.await?;
Configuration
use ;
use Duration;
let config = new
.with_operation_timeout
.with_protocol_version
.with_pool_config;
Use ConnectionConfig::new("redis://host1:6379,host2:6379") with cluster
topology detection enabled for Redis Cluster deployments. Sentinel configuration
is available through SentinelConfig.
Development
Required toolchain:
- Rust 1.82.0 or newer
- Redis available on
localhost:6379for integration tests
Quality gates:
Documentation
Compatibility
- Rust: 1.82.0 or newer
- Redis: 6.0 or newer
- Platforms: Linux, macOS, Windows
- Runtime: Tokio
License
This project is licensed under the MIT License. See LICENSE-MIT.