Rust

multiplexing

Module

[Multiplexing]: many tasks over one Redis connection.

Contents

use utopia_cache::Multiplexing;
Rust
pub struct Multiplexing<K = Json>

Many tasks sharing one Redis connection: each command is queued and written under a send lock, so the queue's order is the wire order, and one reader task hands every reply to the next caller in the queue (Redis answers in order). Entries are stored like crate::Redis stores them, with the same leases.

Two deadlines keep a slow server apart from a dead one. A caller that waits longer than read_timeout fails with Error::Timeout and leaves the connection alone (its slot stays queued so later replies stay aligned). When nothing at all has arrived for liveness_timeout while callers wait, the connection is torn down (Error::Idle) and the next call reconnects. Other connection failures are retried once on a new connection.

Rust
use php_std::types::Value;
use utopia_cache::{Adapter, Multiplexing, MultiplexingOptions};

let cache = Multiplexing::connect(MultiplexingOptions::new("localhost", 6379)).await?;
cache.save("docs:user:2", &Value::from("Ada"), "", 0).await?;
assert_eq!(cache.load("docs:user:2", 60, "").await?, Some(Value::from("Ada")));
cache.purge("docs:user:2", "").await?;
cache.disconnect();
Compiles in CI; needs a running service to execute.
Also implements Drop, Transport.
use utopia_cache::MultiplexingOptions;
Rust
pub struct MultiplexingOptions

Settings of a Multiplexing connection; defaults in parentheses.