DEV Community

Cover image for Meet Fred: The most awesome Redis client for Rust.

Posted on

Meet Fred: The most awesome Redis client for Rust.


GitHub logo aembke /

An async Redis client for Rust.


License License CircleCI API docs

An async Redis client for Rust.


use fred::prelude::*;
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?;
  let _: () = client.set("foo", "bar", None, None, false).await?;
  // or use turbofish to declare response types
  println!("Foo: {:?}", client.get::<String, _>("foo").await?);
Enter fullscreen mode Exit fullscreen mode

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)