Expand description
Fred
An async client library for Redis based on Tokio and Futures.
Examples
ⓘ
use fred::prelude::*;
use std::future::Future;
#[tokio::main]
async fn main() -> Result<(), RedisError> {
let config = RedisConfig::default();
let policy = ReconnectPolicy::default();
let client = RedisClient::new(config);
// connect to the server, returning a handle to a task that drives the connection
let jh = client.connect(Some(policy));
// wait for the client to connect
let _ = client.wait_for_connect().await?;
let _ = client.flushall(false).await?;
// convert responses to many common Rust types
let foo: Option<String> = client.get("foo").await?;
assert_eq!(foo, None);
let _: () = client.set("foo", "bar", None, None, false).await?;
// or use turbofish to declare types. the first type is always the response.
println!("Foo: {:?}", client.get::<String, _>("foo".to_owned()).await?);
// or use a lower level interface for responses to defer parsing, etc
let foo: RedisValue = client.get("foo").await?;
assert!(foo.is_string());
let _ = client.quit().await?;
// and/or wait for the task driving the connection to finish
let _ = jh.await;
Ok(())
}
See the github repository for more examples.
Modules
The primary interface for communicating with the Redis server.
Error structs returned by Redis commands.
Utility functions for manipulating global values that can affect performance.
monitor
monitor
An interface to run the MONITOR
command.
Client pooling structs.
Convenience module to use
a RedisClient
, RedisError
, and any argument types.
sentinel
sentinel-client
An interface for interacting directly with sentinel nodes.
The structs and enums used by the Redis client.