85 releases (48 stable)

new 9.0.1 Apr 15, 2024
8.0.6 Mar 31, 2024
8.0.4 Feb 27, 2024
7.1.2 Jan 12, 2024
0.0.6 Nov 7, 2017

#17 in Database interfaces

Download history 3294/week @ 2023-12-23 5820/week @ 2023-12-30 19476/week @ 2024-01-06 25675/week @ 2024-01-13 25530/week @ 2024-01-20 31644/week @ 2024-01-27 39904/week @ 2024-02-03 32320/week @ 2024-02-10 46777/week @ 2024-02-17 48121/week @ 2024-02-24 43669/week @ 2024-03-02 50696/week @ 2024-03-09 50422/week @ 2024-03-16 51844/week @ 2024-03-23 49969/week @ 2024-03-30 46603/week @ 2024-04-06

207,205 downloads per month
Used in 19 crates (16 directly)

MIT license

1MB
31K SLoC

Fred

License License CircleCI Crates.io API docs

An async Redis client for Rust and Tokio.

Example

use fred::prelude::*;

#[tokio::main]
async fn main() -> Result<(), RedisError> {
  let client = RedisClient::default();
  client.init().await?;

  // convert responses to many common Rust types
  let foo: Option<String> = client.get("foo").await?;
  assert!(foo.is_none());

  client.set("foo", "bar", None, None, false).await?;
  // or use turbofish to declare response types
  println!("Foo: {:?}", client.get::<String, _>("foo").await?);

  // or use a lower level interface for responses to defer parsing, etc
  let foo: RedisValue = client.get("foo").await?;
  assert_eq!(foo.as_str().unwrap(), "bar");

  client.quit().await?;
  Ok(())
}

See the examples for more.

Features

  • RESP2 and RESP3 protocol modes.
  • Clustered, centralized, and sentinel Redis deployments.
  • TLS via native-tls or rustls.
  • Unix sockets.
  • Efficient automatic pipelining
  • Zero-copy frame parsing
  • Optional reconnection features.
  • Publish-Subscribe and keyspace events interfaces.
  • A round-robin client pooling interface.
  • Lua scripts or functions.
  • Streaming results from the MONITOR command.
  • Custom commands.
  • Streaming interfaces for scanning functions.
  • Transactions
  • Pipelining
  • Client Tracking
  • A RedisJSON interface.
  • A round-robin cluster replica routing interface.
  • A subscriber client that will automatically manage channel subscriptions.
  • Tracing

Build Features

Name Default Description
transactions x Enable a Transaction interface.
enable-native-tls Enable TLS support via native-tls.
enable-rustls Enable TLS support via rustls.
vendored-openssl Enable the native-tls/vendored feature.
metrics Enable the metrics interface to track overall latency, network latency, and request/response sizes.
full-tracing Enable full tracing support. This can emit a lot of data.
partial-tracing Enable partial tracing support, only emitting traces for top level commands and network latency.
blocking-encoding Use a blocking task for encoding or decoding frames. This can be useful for clients that send or receive large payloads, but requires a multi-thread Tokio runtime.
custom-reconnect-errors Enable an interface for callers to customize the types of errors that should automatically trigger reconnection logic.
monitor Enable an interface for running the MONITOR command.
sentinel-client Enable an interface for communicating directly with Sentinel nodes. This is not necessary to use normal Redis clients behind a sentinel layer.
sentinel-auth Enable an interface for using different authentication credentials to sentinel nodes.
subscriber-client Enable a subscriber client interface that manages channel subscription state for callers.
serde-json Enable an interface to automatically convert Redis types to JSON via serde-json.
mocks Enable a mocking layer interface that can be used to intercept and process commands in tests.
dns Enable an interface that allows callers to override the DNS lookup logic.
replicas Enable an interface that routes commands to replica nodes.
default-nil-types Enable a looser parsing interface for nil values.
sha-1 Enable an interface for hashing Lua scripts.
unix-sockets Enable Unix socket support.

Interface Features

The Redis interface has many functions and compile times can add up quickly. Interface features begin with i- and control which public interfaces are built.

Name Default Description
i-all Enable the interfaces included with a basic Redis installation. This does not include redis-stack features.
i-std x Enable the common data structure interfaces (lists, sets, streams, keys, etc).
i-acl Enable the ACL command interface.
i-client Enable the CLIENT command interface.
i-cluster Enable the CLUSTER command interface.
i-config Enable the CONFIG command interface.
i-geo Enable the GEO command interface.
i-hashes Enable the hashes (HGET, etc) command interface.
i-hyperloglog Enable the hyperloglog command interface.
i-keys Enable the main keys (GET, SET, etc) command interface.
i-lists Enable the lists (LPUSH, etc) command interface.
i-scripts Enable the scripting command interfaces.
i-memory Enable the MEMORY command interfaces.
i-pubsub Enable the publish-subscribe command interfaces.
i-server Enable the server control (SHUTDOWN, BGSAVE, etc) interfaces.
i-sets Enable the sets (SADD, etc) interface.
i-sorted-sets Enable the sorted sets (ZADD, etc) interface.
i-slowlog Enable the SLOWLOG interface.
i-streams Enable the streams (XADD, etc) interface.
i-tracking Enable a client tracking interface.
i-time-series Enable a Redis Timeseries. interface.
i-redis-json Enable a RedisJSON interface.
i-redis-stack Enable the Redis Stack interfaces (i-redis-json, i-time-series, etc).

Debugging Features

Name Default Description
debug-ids Enable a global counter used to differentiate commands in logs.
network-logs Enable additional TRACE logs for all frames on all sockets.

Dependencies

~8–24MB
~373K SLoC