TLDR
Fred
An async client for Valkey and Redis
Example
use fred::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Error> {
let config = Config::from_url("redis://localhost:6379/1")?;
let client = Builder::from_config(config)
.with_connection_config(|config| {
config.connection_timeout = Duration::from_secs(5);
config.tcp = TcpConfig {
nodelay: Some(true),
..Default::default()
};
})
.build()?;
client.init().await?;
client.on_error(|(error, server)| async move {
println!("{:?}: Connection error: {:?}", server, error);
Ok(())
});
// convert responses to many
…Back Story
The goto Redis client for Rust is called redis-rs. It has over 3k stars on Github. but I found it very annoying to use because I quickly found out that if you want to set any value you had to get a mutable reference to the underlying client. Which meant great pain to store Redis client in the global scope. People who do not know what a mutable reference is consider the let
keyword in JavaScript. you can mutate or change a variable that is initiated with let
.
The other annoyance I had that it didn't support RedisJson which was a bummer because it is very helpful if you store anything other than String
key value pair.
Fortunately then I found Fred. Fred is a beautiful piece of engineering. It solved all of the problems I had with the redis-rs package. It is async friendly, it supports RedisJson and most importantly it doesn't require a mutable reference to set value.
It also has a lot of other great features. Consider starring the project and spreading the words!
Top comments (0)