Skip to main content

RedisPool

Struct RedisPool 

Source
pub struct RedisPool { /* private fields */ }
Expand description

Shared Redis handle filled during on_startup (mirrors [sova_db::DbPool]).

Implementations§

Source§

impl RedisPool

Source

pub async fn publish( &self, channel: impl AsRef<str>, message: impl AsRef<[u8]>, ) -> Result<i64, RedisError>

PUBLISH channel message — returns subscriber count that received it.

Source

pub async fn subscribe( &self, channels: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<RedisSubscriber, RedisError>

Open a dedicated Pub/Sub connection and subscribe to channels.

Requires the pool URL (set by the crate::Redis plugin). Do not reuse the shared command connection for subscribe.

Source

pub async fn psubscribe( &self, patterns: impl IntoIterator<Item = impl AsRef<str>>, ) -> Result<RedisSubscriber, RedisError>

Pattern subscribe (PSUBSCRIBE), e.g. events:*.

Source

pub async fn enqueue( &self, queue: impl AsRef<str>, message: impl AsRef<[u8]>, ) -> Result<i64, RedisError>

Push onto a list queue (LPUSH). Returns new list length.

Source

pub async fn dequeue( &self, queue: impl AsRef<str>, ) -> Result<Option<Vec<u8>>, RedisError>

Non-blocking pop (RPOP). None if empty.

Source

pub async fn dequeue_wait( &self, queue: impl AsRef<str>, timeout: Duration, ) -> Result<Option<(String, Vec<u8>)>, RedisError>

Blocking pop (BRPOP). timeout = 0 waits forever.

Returns (queue_name, payload) or None on timeout.

Source§

impl RedisPool

Source

pub fn new() -> Self

Source

pub fn is_fake(&self) -> bool

Source

pub fn fake(&self) -> Option<Arc<FakeRedis>>

Source

pub fn set_fake(&self, fake: FakeRedis)

Source

pub fn set_url(&self, url: impl Into<String>)

Remember REDIS_URL so Pub/Sub can open a dedicated connection.

Source

pub fn url(&self) -> Result<String, RedisError>

Source

pub fn set(&self, conn: ConnectionManager)

Source

pub fn get(&self) -> Result<ConnectionManager, RedisError>

Source

pub fn clear(&self)

Source

pub async fn connect(url: &str) -> Result<ConnectionManager, RedisError>

Connect and ping; used by the plugin and tests.

Source

pub async fn subscribe_fake( &self, channel: impl AsRef<str>, ) -> Result<FakeSubscriber, RedisError>

Trait Implementations§

Source§

impl Clone for RedisPool

Source§

fn clone(&self) -> Self

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 Default for RedisPool

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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