Meet Fred: The most awesome Redis client for Rust.

tausifcreates

Tausif

Posted on October 18, 2023

Meet Fred: The most awesome Redis client for Rust.

TLDR

GitHub logo aembke / fred.rs

An async Redis client for Rust.

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(())
}
Enter fullscreen mode Exit fullscreen mode

See the examples

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!

💖 💪 🙅 🚩
tausifcreates
Tausif

Posted on October 18, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related