connection
ModuleRedis connections the Redis broker runs on: a single server
(Redis), a cluster (RedisCluster), and a wrapper that serialises
commands from concurrent tasks (Locking).
Contents
3 submodules, and what the module defines itself.
use utopia_queue::connection::Connection;pub trait Connection: Send + SyncA connection to Redis: the commands the Redis broker and its callers use.
Implementors provide Connection::query, Connection::execute,
Connection::ping and Connection::close; every other method is
built on query, so a wrapper that overrides those four (as
Locking does) covers them all.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>A boxed, sendable future.
pub type Reply = ::redis::ValueA Redis reply.
connection::locking
Own pageSerialised access to a shared connection.
use utopia_queue::connection::locking::Locking;pub struct Locking<C, L = Mutex>Wraps a Connection and runs every command behind one lock, so tasks
sharing the connection cannot interleave on it. The lock is waited on
forever: a command is never dropped because the connection is busy.
use utopia_queue::connection::{Locking, Redis};
let shared = Locking::new(Redis::new("localhost", 6379));connection::redis
Own pageOne Redis server.
use utopia_queue::connection::redis::Redis;pub struct RedisA connection to one Redis server, opened on first use and reopened after the socket is lost.
Connecting is retried five times with jittered exponential backoff. A
command that fails because the socket went away drops the connection; a
command safe to repeat (reads, SET, DEL, LREM) is run once more on
a fresh one, others (pops, pushes, counters) report the error, because the
server may already have applied them.
use utopia_queue::connection::{Connection, Redis};
let redis = Redis::new("localhost", 6379);
redis.left_push(b"jobs", b"payload").await?;
assert_eq!(redis.list_size(b"jobs").await?, 1);connection::redis_cluster
Own pageA Redis Cluster.
use utopia_queue::connection::redis_cluster::RedisCluster;pub struct RedisClusterA connection to a Redis Cluster through its seed nodes.
Scripts run with EVAL on the node owning their keys, so every key of
one script must share a hash tag: give queues a namespace like
{utopia-queue}. A script whose keys do not is refused before anything
is sent.
use utopia_dsn::Dsn;
use utopia_queue::connection::RedisCluster;
let dsn = Dsn::parse("redis-cluster://[node-1:7000;node-2]:7001")?;
let cluster = RedisCluster::from_dsn(&dsn, -1.0, -1.0)?;
assert_eq!(cluster.seeds(), ["node-1:7000", "node-2:7001"]);