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")
.awaitThe 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
- Redis
Idempotency Store IdempotencyStorein Redis. Pair it withIdempotency::shared_seedso all instances hash scopes and payloads alike. Fails closed: when Redis is unreachable requests get503.- Redis
Rate Limit Store RateLimitStorein Redis. Fails open: when Redis is unreachable requests are allowed.- Redis
Session Store SessionStorein Redis: one JSON string per session with an expiry
Enums§
- Value
- A reply from Redis