Skip to main content

RedisBackplane

Struct RedisBackplane 

Source
pub struct RedisBackplane { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

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(),
)?;
Source

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

Source§

fn clone(&self) -> RedisBackplane

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RedisBackplane

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more