Home

Awesome

Fred

License License CircleCI Crates.io API docs

An async client for Redis and Valkey

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?);

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

See the examples for more.

Features

See the build features for more information.

Client Features

NameDefaultDescription
transactionsxEnable a Transaction interface.
enable-native-tlsEnable TLS support via native-tls.
enable-rustlsEnable TLS support via rustls with the default crypto backend features.
enable-rustls-ringEnable TLS support via rustls and the ring crypto backend.
vendored-opensslEnable the native-tls/vendored feature.
metricsEnable the metrics interface to track overall latency, network latency, and request/response sizes.
full-tracingEnable full tracing support. This can emit a lot of data.
partial-tracingEnable partial tracing support, only emitting traces for top level commands and network latency.
blocking-encodingUse 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-errorsEnable an interface for callers to customize the types of errors that should automatically trigger reconnection logic.
monitorEnable an interface for running the MONITOR command.
sentinel-clientEnable an interface for communicating directly with Sentinel nodes. This is not necessary to use normal Redis clients behind a sentinel layer.
sentinel-authEnable an interface for using different authentication credentials to sentinel nodes.
subscriber-clientEnable a subscriber client interface that manages channel subscription state for callers.
serde-jsonEnable an interface to automatically convert Redis types to JSON via serde-json.
mocksEnable a mocking layer interface that can be used to intercept and process commands in tests.
dnsEnable an interface that allows callers to override the DNS lookup logic.
replicasEnable an interface that routes commands to replica nodes.
default-nil-typesEnable a looser parsing interface for nil values.
sha-1Enable an interface for hashing Lua scripts.
unix-socketsEnable Unix socket support.

Interface Features

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

NameDefaultDescription
i-allEnable the interfaces included with a basic Redis or Valkey installation. This does not include i-redis-stack features.
i-stdxEnable the common data structure interfaces (lists, sets, streams, keys, etc).
i-aclEnable the ACL command interface.
i-clientEnable the CLIENT command interface.
i-clusterEnable the CLUSTER command interface.
i-configEnable the CONFIG command interface.
i-geoEnable the GEO command interface.
i-hashesEnable the hashes (HGET, etc) command interface.
i-hyperloglogEnable the hyperloglog command interface.
i-keysEnable the main keys (GET, SET, etc) command interface.
i-listsEnable the lists (LPUSH, etc) command interface.
i-scriptsEnable the scripting command interfaces.
i-memoryEnable the MEMORY command interfaces.
i-pubsubEnable the publish-subscribe command interfaces.
i-serverEnable the server control (SHUTDOWN, BGSAVE, etc) interfaces.
i-setsEnable the sets (SADD, etc) interface.
i-sorted-setsEnable the sorted sets (ZADD, etc) interface.
i-slowlogEnable the SLOWLOG interface.
i-streamsEnable the streams (XADD, etc) interface.
i-trackingEnable a client tracking interface.
i-time-seriesEnable a Redis Timeseries interface.
i-redis-jsonEnable a RedisJSON interface.
i-redisearchEnable a RediSearch interface.
i-redis-stackEnable the Redis Stack interfaces (i-redis-json, i-time-series, etc).

Debugging Features

NameDefaultDescription
debug-idsEnable a global counter used to differentiate commands in logs.
network-logsEnable additional TRACE logs for all frames on all sockets.