Struct taskline::backends::redis::RedisBackend
source · 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
impl RedisBackend
sourcepub fn new(
client: Client,
queue_key: String,
read_batch_size: usize,
autodelete: bool
) -> Self
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- iftrue, tasks will be deleted from queue after reading. Iffalse, tasks should be deleted explicitly from queue after reading withRedisBackend::delete. New in version 0.5.0.
sourcepub async fn read(&self, score: &f64) -> Result<Vec<String>, RedisError>
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.
sourcepub async fn write(&self, task: &String, score: &f64) -> Result<(), RedisError>
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.
sourcepub async fn delete(&self, task: &String) -> Result<(), RedisError>
pub async fn delete(&self, task: &String) -> Result<(), RedisError>
Delete a task from queue.
New in version 0.5.0.
sourcepub async fn is_redis_version_ok(&self) -> Result<bool, RedisError>
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
impl Clone for RedisBackend
source§fn clone(&self) -> RedisBackend
fn clone(&self) -> RedisBackend
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl CommitBackend<String, RedisError> for RedisBackend
impl CommitBackend<String, RedisError> for RedisBackend
source§impl DequeuBackend<String, f64, RedisError> for RedisBackend
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,
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
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,
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.