Skip to main content

Crate redust

Crate redust 

Source
Expand description

§Redust

Redust Documentation

A simple Redis client for Rust.

Redust is an async Redis client built on tokio. It speaks RESP using redust-resp, which is re-exported as redust::resp.

  • Simple: send any command as a list of arguments and get back RESP Data.
  • Idiomatic: a Connection is a TryStream and Sink of RESP data, so it works with the futures combinators you already know, including for PubSub.
  • serde-powered: deserialize responses into your own types with resp::from_data.
  • Pipelining: send many commands at once with Connection::pipeline.

§Usage

use redust::{resp::{from_data, Data}, Connection};

#[tokio::main]
async fn main() -> redust::Result<()> {
    let mut conn = Connection::new("localhost:6379").await?;

    conn.cmd(["SET", "hello", "world"]).await?;
    let res: Data = conn.cmd(["GET", "hello"]).await?;

    let value: String = from_data(res)?;
    assert_eq!(value, "world");

    let results = conn.pipeline([["INCR", "count"], ["INCR", "count"]]).await?;
    assert_eq!(results.len(), 2);

    Ok(())
}

§Features

All features are disabled by default.

  • command: type-safe commands, such as Hello and PubSub commands
  • model: serde models for complex Redis responses, such as PubSub messages and stream IDs
  • pool: connection pooling with deadpool
  • script: Lua scripts invoked by their SHA1 hash, loading them as necessary

§Benchmarks

End-to-end comparison with redis-rs 1.8.0 and fred 10.1.0, each using a single connection driven sequentially. Times are criterion’s median estimate per iteration; lower is better.

Benchmarkredustredis-rsfred
PING307 µs317 µs324 µs
SET + GET, 16 B622 µs632 µs651 µs
SET + GET, 1 KiB615 µs647 µs642 µs
SET + GET, 64 KiB44.0 ms44.0 ms44.1 ms
pipeline, 10 × SET316 µs331 µs523 µs
pipeline, 100 × SET441 µs498 µs1.29 ms
pipeline, 1000 × SET1.30 ms1.74 ms8.17 ms

Single commands are dominated by network round trips, so all three clients are within a few percent of each other; the 64 KiB case is bound by TCP delayed-ACK stalls (~40 ms) for every client. Pipelining is where client overhead shows: redust is about 25% faster than redis-rs and 6× faster than fred at 1000 commands.

Measured on an AMD Ryzen 9 3900X running Windows 10 and Rust 1.95, against Redis 8.10.3 in Docker Desktop on the same machine. Benchmarks for RESP parsing and encoding are in the redust-resp README. To reproduce, see the benches crate.

Re-exports§

pub use redust_resp as resp;

Modules§

command
Command trait + implementations.
model
Redis models.
pool
Manage Redis connections with deadpool.
script
Script utilities to handle SHA1 hash-based invocation.

Structs§

Codec
Tokio codec with Encoder and Decoder for RESP.
Connection
A TCP connection to a Redis server.

Type Aliases§

Error
Static resp::Error returned from Connection and Codec.
Result
Result with an error type defaulting to Error.
SharedConnection
A Connection that can be shared across threads.