Redis (Caching)
Use case
You need a cache or key-value store: session data, rate limiting, or simple key-value lookups. redis is the standard Redis client for Rust; use the tokio-comp feature for async.
In C#: Like StackExchange.Redis: connect, get/set, or use IDistributedCache. In Rust, you get a connection and run commands; results are typed.
Connecting
Use redis::Client::open("redis://127.0.0.1/") and .get_multiplexed_async_connection().await to get a connection. A multiplexed connection can be cloned and shared across tasks (one underlying socket), so it doubles as a lightweight pool; for more control use ConnectionManager (the connection-manager feature) or a dedicated pool crate.
use redis::AsyncCommands;
let client = redis::Client::open("redis://127.0.0.1/")?;
let mut conn = client.get_multiplexed_async_connection().await?;In C#: Like ConnectionMultiplexer.Connect("localhost") and getting a database.
GET and SET
Use the connection with the AsyncCommands trait: .set(key, value) and .get(key) return futures; .await them.
// `set` is generic over its return type. When you discard the result, annotate
// it as `()` — otherwise it relies on never-type fallback, which is now an error.
let _: () = conn.set("mykey", "myvalue").await?;
let val: String = conn.get("mykey").await?;In C#: Like db.StringSet("mykey", "myvalue") and db.StringGet("mykey").
TTL and expiry
Use .set_ex(key, value, seconds) to set with an expiry, or .expire(key, seconds) after a set. Use .get(key) as usual; expired keys return nil (None in Rust).
In C#: Like KeyExpire or StringSet with TimeSpan.
Key takeaway
Use redis::Client::open(url) and get_multiplexed_async_connection().await. Bring AsyncCommands into scope and use .set, .get, .set_ex etc. All operations are async and return Result; use ? with an async main (e.g. #[tokio::main]).