redis-oxide
A high-performance, async Redis client for Rust with automatic cluster detection, comprehensive Redis feature support, and flexible connection strategies. Inspired by StackExchange.Redis for .NET.
✨ Features
- 🚀 High Performance: Optimized protocol encoding/decoding with memory pooling
- 🔄 Automatic Topology Detection: Auto-detects Standalone Redis or Redis Cluster
- 🎯 Comprehensive Command Support: Full Redis command coverage including latest features
- 🔗 Flexible Connection Strategies: Multiplexed connections and traditional connection pools
- 📡 Advanced Features: Pub/Sub, Streams, Lua scripting, Transactions, Pipelines
- 🛡️ High Availability: Redis Sentinel support with automatic failover
- 🔧 Protocol Support: Both RESP2 and RESP3 protocols
- ⚡ Async/Await: Fully asynchronous with Tokio runtime
- 🔄 Automatic Reconnection: Smart reconnection with exponential backoff
- 🎨 Type-Safe APIs: Builder patterns and compile-time safety
- 📊 Cross-Platform: Linux, macOS, and Windows support
📦 Installation
Add this to your Cargo.toml:
[]
= "0.2.2"
= { = "1.0", = ["full"] }
🚀 Quick Start
Basic Usage
use ;
async
Redis Cluster
use ;
async
🎯 Core Operations
String Operations
// SET/GET with various options
client.set.await?;
client.set_ex.await?;
client.set_nx.await?; // Only if not exists
client.set_xx.await?; // Only if exists
let value: = client.get.await?;
let values: = client.mget.await?;
// Atomic operations
let new_value: i64 = client.incr.await?;
let new_value: i64 = client.incr_by.await?;
Hash Operations
use HashMap;
// Hash operations
client.hset.await?;
let mut fields = new;
fields.insert;
fields.insert;
client.hset_multiple.await?;
let value: = client.hget.await?;
let all: = client.hget_all.await?;
List Operations
// List operations
client.lpush.await?;
client.rpush.await?;
let items: = client.lrange.await?;
let item: = client.lpop.await?;
let length: i64 = client.llen.await?;
Set Operations
// Set operations
client.sadd.await?;
let members: = client.smembers.await?;
let is_member: bool = client.sismember.await?;
let removed: i64 = client.srem.await?;
Sorted Set Operations
use HashMap;
// Sorted set operations
let mut scores = new;
scores.insert;
scores.insert;
client.zadd.await?;
let members: = client.zrange.await?;
let score: = client.zscore.await?;
let rank: = client.zrank.await?;
🔧 Advanced Features
Pipeline Operations
Batch multiple commands for improved performance:
let mut pipeline = client.pipeline;
pipeline.set;
pipeline.set;
pipeline.get;
pipeline.incr;
let results = pipeline.execute.await?;
Transactions
ACID transactions with optimistic locking:
let mut transaction = client.transaction.await?;
transaction.watch.await?;
transaction.get;
transaction.set;
transaction.set;
let results = transaction.exec.await?;
Lua Scripting
Execute Lua scripts with automatic EVALSHA caching:
use ;
let script = new;
let result: i64 = script.execute.await?;
Pub/Sub Messaging
Real-time messaging with pattern matching:
use PubSub;
let mut pubsub = client.get_pubsub.await?;
// Subscribe to channels
pubsub.subscribe.await?;
pubsub.psubscribe.await?;
// Listen for messages
while let Some = pubsub.next_message.await?
Redis Streams
Event sourcing and stream processing:
use ;
// Add entries to stream
client.xadd.await?;
// Read from stream
let options = new.count.block;
let entries: = client.xread.await?;
// Consumer groups
client.xgroup_create.await?;
let entries = client.xreadgroup.await?;
🏗️ Architecture
Connection Strategies
Multiplexed Connections (Default)
Shares a single connection across multiple tasks for optimal resource usage:
let config = new
.with_strategy;
Connection Pool
Traditional connection pooling for high-throughput scenarios:
let config = new
.with_strategy
.with_pool_config;
Cluster Support
Automatic cluster topology discovery and slot management:
let config = new
.with_cluster_discovery
.with_read_from_replicas;
let client = connect.await?;
// Automatically handles MOVED/ASK redirects
High Availability with Sentinel
let config = new_sentinel.with_sentinel_auth;
let client = connect.await?;
// Automatic failover handling
🛠️ Development
Prerequisites
- Rust 1.82 or later
- Redis server 6.0+ for testing
Setup
# Clone the repository
# Build the project
# Run tests (requires Redis server)
# Run examples
Contributing
We welcome contributions! Please:
- Fork and clone the repository
- Create a feature branch from
main - Follow code style: Run
cargo fmtandcargo clippy - Add tests for new features
- Update documentation as needed
- Submit a pull request with a clear description
Code Quality
Before submitting a PR, ensure:
# Format code
# Run clippy
# Run tests
# Build release
🎯 Roadmap
Current Version (v0.2.2)
- ✅ Basic Redis operations support
- ✅ Cluster mode with automatic topology detection
- ✅ Connection pooling strategies (Multiplexed & Connection Pool)
- ✅ Pub/Sub messaging and Redis Streams
- ✅ Lua scripting with EVALSHA caching
- ✅ Sentinel support for high availability
- ✅ Transactions and Pipelines
Upcoming Features
v0.3.0 - Performance & Memory Optimizations
- Zero-copy parsing for RESP3
- Memory pooling and buffer recycling
- Adaptive connection pool sizing
- Comprehensive benchmarking suite
v0.4.0 - Monitoring & Observability
- OpenTelemetry integration
- Built-in metrics and health checks
- Distributed tracing support
- Performance monitoring dashboard
⚡ Performance
Redis Oxide is designed for high performance:
- Zero-copy parsing where possible
- Connection multiplexing reduces overhead
- Automatic pipelining for bulk operations
- RESP3 protocol support for reduced bandwidth
- Memory pooling to minimize allocations
🔧 Configuration
Connection Configuration
use ;
let config = new
.with_strategy
.with_pool_config
.with_connect_timeout
.with_response_timeout
.with_reconnect_attempts
.with_password
.with_database;
SSL/TLS Support
let config = new
.with_tls_config;
🐛 Error Handling
Redis Oxide provides comprehensive error types:
use RedisError;
match client.get.await
🔍 Examples
Check out the examples/ directory for complete examples:
basic_usage.rs- Basic Redis operationscluster_usage.rs- Redis Cluster featurespool_strategies.rs- Connection strategies
📖 Documentation
- API Documentation: https://docs.rs/redis-oxide
- Examples: See
examples/directory - Contributing Guide: See above development section
⚖️ Compatibility
Rust Version Support
- MSRV: Rust 1.82.0
- Edition: 2021 (stable)
- Platforms: Linux, macOS, Windows
Redis Version Support
- Redis 6.0+: Full support
- Redis 7.0+: Recommended for optimal performance
- Redis Cluster: Supported
- Redis Sentinel: Supported
Known Issues
There is a temporary ecosystem issue with the home crate and edition2024 feature flag. This affects transitive dependencies but not the library functionality. Use Rust 1.82.0+ to avoid this issue.
📄 License
This project is licensed under either of the following, at your option:
🤝 Support
- Documentation: https://docs.rs/redis-oxide
- Issues: https://github.com/nghiaphamln/redis-oxide/issues
- Discussions: https://github.com/nghiaphamln/redis-oxide/discussions
Made with ❤️ by the Redis Oxide team