pub struct RedisCacheStore { /* private fields */ }Expand description
The cache operations (Java RedisCacheStore).
Commands that are safe to run twice (SETEX, GET, MGET, MPUT, DEL,
LLEN) go through the backend’s idempotent path and are retried once when
the connection was lost to a restart; SET NX, RPUSH and LPOP are never
replayed (redis_connection::backend, Lifecycle).
Implementations§
Source§impl RedisCacheStore
impl RedisCacheStore
Sourcepub fn new(
backend: RedisBackend,
key_prefix: impl Into<String>,
default_ttl_seconds: u64,
) -> Self
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.
Sourcepub fn default_ttl_seconds(&self) -> u64
pub fn default_ttl_seconds(&self) -> u64
The default TTL (seconds) applied when a write omits one.
Sourcepub fn backend(&self) -> &RedisBackend
pub fn backend(&self) -> &RedisBackend
The backend this store runs on (diagnostics: cluster(), endpoint()).
Sourcepub async fn put(
&self,
key: Option<&str>,
value: &[u8],
ttl_seconds: u64,
) -> Result<(), AppError>
pub async fn put( &self, key: Option<&str>, value: &[u8], ttl_seconds: u64, ) -> Result<(), AppError>
SETEX key ttl value.
Sourcepub async fn get(&self, key: Option<&str>) -> Result<Option<Vec<u8>>, AppError>
pub async fn get(&self, key: Option<&str>) -> Result<Option<Vec<u8>>, AppError>
GET key — the value, or None on a miss.
Sourcepub async fn mget(
&self,
keys: &[String],
) -> Result<Vec<(String, Vec<u8>)>, AppError>
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.
Sourcepub async fn mput(
&self,
entries: &[(String, Vec<u8>)],
ttl_seconds: u64,
) -> Result<(), AppError>
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.
Sourcepub async fn delete(&self, key: Option<&str>) -> Result<i64, AppError>
pub async fn delete(&self, key: Option<&str>) -> Result<i64, AppError>
DEL key — the number of keys removed (0 or 1).
Sourcepub async fn put_if_absent(
&self,
key: Option<&str>,
value: &[u8],
ttl_seconds: u64,
) -> Result<bool, AppError>
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.
Sourcepub async fn list_push(
&self,
key: Option<&str>,
value: &[u8],
ttl_seconds: u64,
) -> Result<i64, AppError>
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.