Skip to main content

Module redis

Module redis 

Source
Expand description

Minimal Redis client and Redis-backed stores (feature redis)

Sessions, rate limits and idempotency keys live in process memory by default, so a second instance sees none of them. With this feature the same middleware keeps its state in Redis, shared by every instance:

use ullun::prelude::*;
use ullun::redis::{Redis, RedisSessionStore};
use ullun::session::SessionLayer;

let redis = Redis::from_url("redis://127.0.0.1:6379/0")?;
App::new()
    .middleware(SessionLayer::with_store(RedisSessionStore::new(redis)))
    .run("127.0.0.1:3000")
    .await

The client speaks RESP2 over plain TCP with a small connection pool and brings no dependencies. It supports redis://[user:password@]host[:port][/db] and is meant for the stores here; for anything else use a full client and implement the store traits (SessionStore, IdempotencyStore, RateLimitStore) yourself. TLS (rediss://) is not supported: terminate it with a local proxy or keep Redis on a private network.

Failure behavior is chosen per store: a session store that cannot reach Redis behaves as if the session does not exist, the rate limiter fails open (requests are let through), idempotency fails closed (503) because running a payment twice is worse than refusing it.

Structs§

Cmd
A command under construction
Redis
A Redis server and a pool of connections to it
RedisIdempotencyStore
IdempotencyStore in Redis. Pair it with Idempotency::shared_seed so all instances hash scopes and payloads alike. Fails closed: when Redis is unreachable requests get 503.
RedisRateLimitStore
RateLimitStore in Redis. Fails open: when Redis is unreachable requests are allowed.
RedisSessionStore
SessionStore in Redis: one JSON string per session with an expiry

Enums§

Value
A reply from Redis