Skip to main content

RedisCacheStore

Struct RedisCacheStore 

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

The cache operations (Java RedisCacheStore).

Implementations§

Source§

impl RedisCacheStore

Source

pub fn new( backend: RedisBackend, key_prefix: impl Into<String>, default_ttl_seconds: u64, ) -> Self

backend is the standalone-or-cluster backend (one shared, multiplexed connection); key_prefix is prepended to every key (blank = none); default_ttl_seconds applies to writes that do not specify one.

Source

pub fn default_ttl_seconds(&self) -> u64

The default TTL (seconds) applied when a write omits one.

Source

pub fn backend(&self) -> &RedisBackend

The backend this store runs on (diagnostics: cluster(), endpoint()).

Source

pub async fn put( &self, key: Option<&str>, value: &[u8], ttl_seconds: u64, ) -> Result<(), AppError>

SETEX key ttl value.

Source

pub async fn get(&self, key: Option<&str>) -> Result<Option<Vec<u8>>, AppError>

GET key — the value, or None on a miss.

Source

pub async fn mget( &self, keys: &[String], ) -> Result<Vec<(String, Vec<u8>)>, AppError>

MGET k1 k2 … — misses omitted, request order kept, keys returned without the prefix. On a cluster the keys may span slots; the cluster client scatter-gathers the request.

Source

pub async fn mput( &self, entries: &[(String, Vec<u8>)], ttl_seconds: u64, ) -> Result<(), AppError>

Bulk write as a pipelined batch of single-key SETEX — one round trip, each key keeping its TTL (raw MSET sets none). Non-atomic across the map, and each key routes to its own slot, so the map may span cluster slots freely.

Source

pub async fn delete(&self, key: Option<&str>) -> Result<i64, AppError>

DEL key — the number of keys removed (0 or 1).

Source

pub async fn put_if_absent( &self, key: Option<&str>, value: &[u8], ttl_seconds: u64, ) -> Result<bool, AppError>

SET key value NX EX ttl — atomic put-if-absent with a TTL in one command (not SETNX then EXPIRE, which leaves a TTL-less key if the process dies between them). true if stored, false if the key existed.

Source

pub async fn list_push( &self, key: Option<&str>, value: &[u8], ttl_seconds: u64, ) -> Result<i64, AppError>

RPUSH key value then EXPIRE key ttl as one atomic MULTI/EXEC step (so the list key is never left TTL-less). The new list length.

Source

pub async fn list_pop( &self, key: Option<&str>, ) -> Result<Option<Vec<u8>>, AppError>

LPOP key — destructive: the oldest value, or None when the list is empty.

Source

pub async fn list_len(&self, key: Option<&str>) -> Result<i64, AppError>

LLEN key — the list length (0 for an absent list).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V