pub struct RedisBackend { /* private fields */ }
Expand description

Redis backend. It implements both DequeuBackend and EnqueuBackend traits. You can use score to sort tasks in queue. Usually it is unix timestamp.

Implementations§

source§

impl RedisBackend

source

pub fn new( client: Client, queue_key: String, read_batch_size: usize, autodelete: bool ) -> Self

Create new instance of RedisBackend.

It requires redis::Client instance, redis key used to store tasks and number of tasks to read in one batch. It also creates lua script used to pop tasks from redis.

  • client - redis client.
  • queue_key - redis key is used to store tasks.
  • read_batch_size - number of tasks to read in one batch.
  • autodelete - if true, tasks will be deleted from queue after reading. If false, tasks should be deleted explicitly from queue after reading with RedisBackend::delete. New in version 0.5.0.
source

pub async fn read(&self, score: &f64) -> Result<Vec<String>, RedisError>

Calls lua script to pop tasks from redis. If there are no tasks in queue it returns empty vector. If there are no tasks with score less than score, returns empty vector.

source

pub async fn write(&self, task: &String, score: &f64) -> Result<(), RedisError>

Adds a task to redis. It uses score to sort tasks in queue. Usually it is unix timestamp.

source

pub async fn delete(&self, task: &String) -> Result<(), RedisError>

Delete a task from queue.

New in version 0.5.0.

source

pub async fn is_redis_version_ok(&self) -> Result<bool, RedisError>

Check redis version.

New in version 0.6.0.

Trait Implementations§

source§

impl Clone for RedisBackend

source§

fn clone(&self) -> RedisBackend

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl CommitBackend<String, RedisError> for RedisBackend

source§

fn commit<'life0, 'life1, 'async_trait>( &'life0 self, task: &'life1 String ) -> Pin<Box<dyn Future<Output = Result<(), RedisError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a task from queue.

New in version 0.5.1.

source§

impl DequeuBackend<String, f64, RedisError> for RedisBackend

source§

fn dequeue<'life0, 'life1, 'async_trait>( &'life0 self, score: &'life1 f64 ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, RedisError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Calls lua script to pop tasks from redis. If there are no tasks in queue it returns empty vector. If there are no tasks with score less than score, returns empty vector.

source§

impl EnqueuBackend<String, f64, RedisError> for RedisBackend

source§

fn enqueue<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task: &'life1 String, score: &'life2 f64 ) -> Pin<Box<dyn Future<Output = Result<(), RedisError>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Adds a task to redis. It uses score to sort tasks in queue. Usually it is unix timestamp.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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