DEV Community

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

Posted on

1 1 1

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!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More