Expand description
Fred
An async Redis client for Rust.
Example
use fred::prelude::*;
#[tokio::main]
async fn main() -> Result<(), RedisError> {
let client = RedisClient::default();
let _ = client.connect();
let _ = client.wait_for_connect().await?;
// convert responses to many common Rust types
let foo: Option<String> = client.get("foo").await?;
assert!(foo.is_none());
let _: () = 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");
let _ = client.quit().await?;
Ok(())
}
See the examples for more.
Features
- RESP2 and RESP3 protocol modes.
- Clustered, centralized, and sentinel Redis deployments.
- TLS connections via
native-tls
and/orrustls
. - Optional reconnection logic with multiple backoff policies.
- 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
- An optional RedisJSON interface.
- A round-robin cluster replica routing interface.
- An optional pubsub subscriber client that will automatically manage channel subscriptions.
- Tracing
Build Features
Name | Default | Description |
---|---|---|
enable-native-tls | Enable TLS support via native-tls. | |
enable-rustls | Enable TLS support via rustls. | |
vendored-openssl | Enable the native-tls/vendored feature, if possible. | |
ignore-auth-error | x | Ignore auth errors that occur when a password is supplied but not required. |
metrics | Enable the metrics interface to track overall latency, network latency, and request/response sizes. | |
reconnect-on-auth-error | A NOAUTH error is treated the same as a general connection failure and the client will reconnect based on the reconnection policy. This is recommended if callers are using ElastiCache. | |
pool-prefer-active | x | Prefer connected clients over clients in a disconnected state when using the RedisPool interface. |
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 will only work when used with a multi-thread Tokio runtime. | |
network-logs | Enable TRACE level logging statements that will print out all data sent to or received from the server. These are the only logging statements that can ever contain potentially sensitive user data. | |
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 an optional subscriber client that manages channel subscription state for callers. | |
serde-json | Enable an interface to automatically convert Redis types to JSON. | |
auto-client-setname | Automatically send CLIENT SETNAME on each connection associated with a client instance. | |
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. | |
check-unresponsive | Enable additional monitoring to detect unresponsive connections. | |
replicas | Enable an interface that routes commands to replica nodes. | |
client-tracking | Enable a client tracking interface. | |
default-nil-types | Enable a looser parsing interface for nil values. | |
redis-json | Enable an interface for RedisJSON. | |
codec | Enable a lower level framed codec interface for use with tokio-util. | |
sha-1 | Enable an interface for hashing Lua scripts. |
Re-exports
pub extern crate bytes;
pub extern crate bytes_utils;
pub extern crate native_tls;
pub extern crate rustls;
pub extern crate rustls_native_certs;
pub extern crate serde_json;
pub extern crate socket2;
pub extern crate tokio_util;
pub extern crate tracing;
Modules
- Redis client implementations.
- codec
codec
Codecs for use with the tokio codec interface. - Error structs returned by Redis commands.
- Utility functions for reading or changing global config values.
- Traits that implement portions of the Redis interface.
- mocks
mocks
An interface for mocking Redis commands. - monitor
monitor
An interface to run theMONITOR
command. - Convenience module to import a
RedisClient
, all possible interfaces, error types, and common argument types or return value types. - The structs and enums used by the Redis client.
- Utility functions used by the client that may also be useful to callers.
Macros
- Shorthand to create a CustomCommand.
- json_quote
redis-json
A helper macro to wrap a string value in quotes via the json macro.