pub struct RedisBackplane { /* private fields */ }hybrid only.Expand description
A backplane over Redis pub/sub. Each hybrid store has its own channel, <store>:backplane, such
as catalog:backplane, so a node gets only its own stores’ messages. Publishing shares one
connection. Each subscription opens its own connection, on RESP3, and holds up to 8,192
messages its worker hasn’t read. The connection keeps reading, so Redis’s limit on slow
subscribers never applies: a worker that falls further behind loses its subscription instead,
so the node clears its local layer and subscribes again, rather than messages piling up or
getting lost without a sign.
Redis delivers a message to subscribers on every database, so two deployments that share a
server need different store names, such as prod:catalog and staging:catalog, even on
separate databases.
On a cluster, use cluster, or connect to any one node:
classic pub/sub reaches every node. While that node is down, subscribing fails and the hybrid
store reads from Redis.
Implementations§
Source§impl RedisBackplane
impl RedisBackplane
Sourcepub async fn connect(
info: impl IntoConnectionInfo,
) -> Result<RedisBackplane, RedisCacheError>
pub async fn connect( info: impl IntoConnectionInfo, ) -> Result<RedisBackplane, RedisCacheError>
Opens the publish connection to one server or any node of a cluster, built with
connection_config. info is a URL, such as redis://127.0.0.1:6379, or a
redis::ConnectionInfo. Each subscription opens its own connection later.
Sourcepub async fn from_client(
client: Client,
) -> Result<RedisBackplane, RedisCacheError>
pub async fn from_client( client: Client, ) -> Result<RedisBackplane, RedisCacheError>
Like connect, on a client built by hand, such as one from
redis::Client::build_with_tls that trusts a private CA or shows a client certificate.
Sourcepub fn sentinel(sentinel: SentinelConnection) -> RedisBackplane
pub fn sentinel(sentinel: SentinelConnection) -> RedisBackplane
Publishes and subscribes on the primary Sentinel names. Publishing shares the store’s
connection, which moves after a failover. Every heartbeat_timeout_ms, each subscription
also asks Sentinel for the primary, which moves the shared connection there
(SentinelConnection::primary_client), and ends once the primary is another server, so
the node subscribes again on the new one. Its own heartbeats can’t show this: a demoted
primary still delivers what is published on it. Redis Sentinel closes client connections on
a failover itself, but Dragonfly refuses the command it uses (CLIENT KILL TYPE).
Give the store and the backplane one connection, so a write that finds the old primary demoted moves both:
use sisa_caching_hybrid::{HybridCacheSettings, HybridCacheStore, RedisBackplane};
use sisa_caching_redis::{
RedisCacheStore, SentinelConnection,
redis::sentinel::{SentinelClient, SentinelServerType},
};
let sentinel = SentinelClient::build(
vec!["redis://10.0.0.1:26379", "redis://10.0.0.2:26379"],
String::from("mymaster"),
None,
SentinelServerType::Master,
)?;
let conn = SentinelConnection::connect(sentinel).await?;
let cache = HybridCacheStore::new(
RedisCacheStore::new("app", conn.clone())?,
RedisBackplane::sentinel(conn),
&HybridCacheSettings::default(),
)?;Sourcepub async fn cluster(
client: ClusterClient,
) -> Result<RedisBackplane, RedisCacheError>
pub async fn cluster( client: ClusterClient, ) -> Result<RedisBackplane, RedisCacheError>
Publishes and subscribes through a cluster client, with sharded pub/sub (SPUBLISH,
SSUBSCRIBE). Build client with ProtocolVersion::RESP3: a subscription on a cluster
connection gets its messages as RESP3 pushes.
The channel lives on the node that owns its slot. When the slot moves, Redis and Valkey end
the subscription, so the node subscribes again on the new owner and clears its local
layer. Garnet keeps it on the old node, where it gets nothing, so the node’s own heartbeats
stop coming back and it does the same within heartbeat_timeout_ms. Dragonfly’s cluster
mode needs sharded pub/sub: it has no classic pub/sub.
Trait Implementations§
Source§impl Clone for RedisBackplane
impl Clone for RedisBackplane
Source§fn clone(&self) -> RedisBackplane
fn clone(&self) -> RedisBackplane
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more