Skip to main content

RedisStore

Struct RedisStore 

Source
pub struct RedisStore { /* private fields */ }
Expand description

Redis-backed store. Connections are pooled internally (r2d2 for both single-node and cluster; the redis crate implements r2d2::ManageConnection for ClusterClient directly).

Implementations§

Source§

impl RedisStore

Source

pub fn connect(url: &str) -> Result<Self, StateError>

Connect to url (e.g. redis://127.0.0.1:6379). Comma-separated URLs select Redis Cluster mode.

Trait Implementations§

Source§

impl StateStore for RedisStore

Source§

fn refund(&self, key: &str, amount: u64)

Round-33 F1: saturating refund via DECRBY + a MAX(0) clamp. Best-effort — errors are silently swallowed so a Redis blip on the compensation path can never turn a lost-race response into a 5xx.

Round-34 F1: NEVER resurrect a key that was already DEL’d by a concurrent remove_prefix. The prior implementation called DECRBY on the raw key: Redis initialises a missing key to 0 first, so DECRBY returned -amount and the MAX(0) clamp branch did SET key 0 (no EX), producing a permanent TTL-less key. Under the round-33 lost-claim- plus-idle-close ordering (mcp_call sandbox-gate debit races with the reconciler’s clear_budget_state), the refund path leaked one-to-three TTL-less keys per session — attacker-choosable memory growth against the exact class reconciler.rs:341-343 documents as impossible. Fix: gate the whole DECRBY on EXISTS. If the session was cleared, the budget is already gone and there is nothing to compensate; the refund is a silent no-op. If the session is alive, we DECRBY-clamp AND refresh the 24 h TTL to match TRY_SPEND_LUA (a plain DECRBY does not refresh).

Source§

fn add(&self, key: &str, delta: u64) -> Result<u64, StateError>

Add delta to key, returning the new value.
Source§

fn get(&self, key: &str) -> Result<u64, StateError>

Read the current value of key (0 if absent).
Source§

fn try_spend( &self, key: &str, amount: u64, limit: u64, ) -> Result<bool, StateError>

Atomically spend amount from the remaining budget limit - spent(key). Returns Ok(true) and records the spend if the full amount fits, Ok(false) (recording nothing) otherwise.
Source§

fn try_spend_many(&self, spends: &[Spend]) -> Result<Option<usize>, StateError>

Atomically validate and commit every spend, or commit none. Returns the index of the first dimension that would exceed its limit. Read more
Source§

fn remove(&self, key: &str)

Remove a key (session cleanup).
Source§

fn remove_prefix(&self, prefix: &str)

Remove every key beginning with prefix (whole-session cleanup at finalization). Backends with native expiry (e.g. Redis TTLs) may leave this as the default no-op; in-process backends must implement it or session-keyed counters accumulate for the process lifetime.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,