pub struct RedisBroker { /* private fields */ }Expand description
Redis-based broker implementation
Implementations§
Source§impl RedisBroker
impl RedisBroker
Sourcepub fn new(
redis_url: &str,
queue_name: &str,
) -> Result<RedisBroker, CelersError>
pub fn new( redis_url: &str, queue_name: &str, ) -> Result<RedisBroker, CelersError>
Create a new Redis broker with FIFO mode
Sourcepub fn with_mode(
redis_url: &str,
queue_name: &str,
mode: QueueMode,
) -> Result<RedisBroker, CelersError>
pub fn with_mode( redis_url: &str, queue_name: &str, mode: QueueMode, ) -> Result<RedisBroker, CelersError>
Create a new Redis broker with specified queue mode
Sourcepub fn from_config(
config: &RedisConfig,
queue_name: &str,
mode: QueueMode,
) -> Result<RedisBroker, CelersError>
pub fn from_config( config: &RedisConfig, queue_name: &str, mode: QueueMode, ) -> Result<RedisBroker, CelersError>
Create a new Redis broker from a RedisConfig
Sourcepub async fn from_sentinel(
sentinel: &SentinelClient,
queue_name: &str,
mode: QueueMode,
) -> Result<RedisBroker, CelersError>
pub async fn from_sentinel( sentinel: &SentinelClient, queue_name: &str, mode: QueueMode, ) -> Result<RedisBroker, CelersError>
Create a new Redis broker from a SentinelClient (for high availability)
Sourcepub fn with_visibility_timeout(self, timeout_secs: u64) -> RedisBroker
pub fn with_visibility_timeout(self, timeout_secs: u64) -> RedisBroker
Set visibility timeout (default: 300 seconds)
Sourcepub async fn dlq_size(&self) -> Result<usize, CelersError>
pub async fn dlq_size(&self) -> Result<usize, CelersError>
Get the number of tasks in the Dead Letter Queue
Sourcepub async fn inspect_dlq(
&self,
limit: isize,
) -> Result<Vec<SerializedTask>, CelersError>
pub async fn inspect_dlq( &self, limit: isize, ) -> Result<Vec<SerializedTask>, CelersError>
Inspect tasks in the Dead Letter Queue
Sourcepub async fn replay_from_dlq(&self, task_id: &Uuid) -> Result<bool, CelersError>
pub async fn replay_from_dlq(&self, task_id: &Uuid) -> Result<bool, CelersError>
Replay a task from the Dead Letter Queue back to the main queue
Sourcepub async fn clear_dlq(&self) -> Result<usize, CelersError>
pub async fn clear_dlq(&self) -> Result<usize, CelersError>
Clear all tasks from the Dead Letter Queue
Sourcepub fn cancel_channel(&self) -> &str
pub fn cancel_channel(&self) -> &str
Get the cancellation channel name (for workers to subscribe)
Sourcepub async fn create_pubsub(&self) -> Result<PubSub, CelersError>
pub async fn create_pubsub(&self) -> Result<PubSub, CelersError>
Create a PubSub connection for listening to cancellation messages
Sourcepub fn health_checker(&self) -> HealthChecker
pub fn health_checker(&self) -> HealthChecker
Create a health checker for monitoring Redis status
Sourcepub fn queue_controller(&self) -> QueueController
pub fn queue_controller(&self) -> QueueController
Create a queue controller for pause/resume operations
Sourcepub fn deduplicator(&self) -> Deduplicator
pub fn deduplicator(&self) -> Deduplicator
Create a task deduplicator
Sourcepub fn script_manager(&self) -> ScriptManager
pub fn script_manager(&self) -> ScriptManager
Create a script manager for Lua script optimization
Sourcepub fn partition_manager(
&self,
num_partitions: usize,
strategy: PartitionStrategy,
) -> PartitionManager
pub fn partition_manager( &self, num_partitions: usize, strategy: PartitionStrategy, ) -> PartitionManager
Create a partition manager for distributed queues
Sourcepub fn batch_operations(&self) -> BatchOperations
pub fn batch_operations(&self) -> BatchOperations
Create a batch operations handler for advanced batch processing
Sourcepub fn priority_manager(&self) -> PriorityManager
pub fn priority_manager(&self) -> PriorityManager
Create a priority manager for dynamic priority adjustments
Sourcepub fn task_query(&self) -> TaskQuery
pub fn task_query(&self) -> TaskQuery
Create a task query interface for inspecting tasks
Sourcepub fn backup_manager(&self) -> BackupManager
pub fn backup_manager(&self) -> BackupManager
Create a backup manager for queue backup and restore
Sourcepub async fn set_queue_ttl(&self, ttl_secs: u64) -> Result<(), CelersError>
pub async fn set_queue_ttl(&self, ttl_secs: u64) -> Result<(), CelersError>
Set TTL (time-to-live) for tasks in all queues
This helps prevent unbounded queue growth by automatically expiring old tasks. TTL is set in seconds.
Sourcepub async fn cleanup_dlq(
&self,
_max_age_secs: u64,
) -> Result<usize, CelersError>
pub async fn cleanup_dlq( &self, _max_age_secs: u64, ) -> Result<usize, CelersError>
Clean up old tasks from DLQ (older than specified age in seconds)
Sourcepub async fn get_queue_stats(&self) -> Result<QueueStats, CelersError>
pub async fn get_queue_stats(&self) -> Result<QueueStats, CelersError>
Get queue statistics (pending, processing, DLQ, delayed counts)
Sourcepub async fn check_health(&self) -> RedisHealthStatus
pub async fn check_health(&self) -> RedisHealthStatus
Check Redis health status
Sourcepub async fn ping(&self) -> Result<u64, CelersError>
pub async fn ping(&self) -> Result<u64, CelersError>
Ping Redis and return latency in milliseconds
Sourcepub fn visibility_timeout(&self) -> u64
pub fn visibility_timeout(&self) -> u64
Get the visibility timeout in seconds
Sourcepub fn delayed_queue_name(&self) -> &str
pub fn delayed_queue_name(&self) -> &str
Get the delayed queue name
Sourcepub fn processing_queue_name(&self) -> &str
pub fn processing_queue_name(&self) -> &str
Get the processing queue name
Sourcepub fn queue_name(&self) -> &str
pub fn queue_name(&self) -> &str
Get the main queue name
Sourcepub fn queue_names(&self) -> Vec<String>
pub fn queue_names(&self) -> Vec<String>
Get all queue names managed by this broker
Sourcepub async fn queue_exists(&self, queue_name: &str) -> Result<bool, CelersError>
pub async fn queue_exists(&self, queue_name: &str) -> Result<bool, CelersError>
Check if a specific queue exists and has tasks
Sourcepub async fn get_queue_size_by_name(
&self,
queue_name: &str,
) -> Result<usize, CelersError>
pub async fn get_queue_size_by_name( &self, queue_name: &str, ) -> Result<usize, CelersError>
Get the size of a specific queue by name
Sourcepub async fn delete_queue(&self, queue_name: &str) -> Result<(), CelersError>
pub async fn delete_queue(&self, queue_name: &str) -> Result<(), CelersError>
Delete a specific queue (use with caution!)
Sourcepub async fn purge_all_queues(&self) -> Result<usize, CelersError>
pub async fn purge_all_queues(&self) -> Result<usize, CelersError>
Purge all queues (main, processing, DLQ, delayed)
Sourcepub async fn get_all_queue_sizes(
&self,
) -> Result<HashMap<String, usize>, CelersError>
pub async fn get_all_queue_sizes( &self, ) -> Result<HashMap<String, usize>, CelersError>
Get a summary of all queue sizes
Sourcepub async fn recover_processing_tasks(&self) -> Result<usize, CelersError>
pub async fn recover_processing_tasks(&self) -> Result<usize, CelersError>
Move all tasks from processing queue back to main queue
Useful for recovering tasks that were being processed when a worker crashed. Returns the number of tasks moved.
Sourcepub async fn total_task_count(&self) -> Result<usize, CelersError>
pub async fn total_task_count(&self) -> Result<usize, CelersError>
Get the total number of tasks across all queues (main, processing, DLQ, delayed)
Sourcepub async fn is_idle(&self) -> Result<bool, CelersError>
pub async fn is_idle(&self) -> Result<bool, CelersError>
Check if the broker is idle (all queues empty)
Sourcepub async fn estimate_memory_usage(&self) -> Result<usize, CelersError>
pub async fn estimate_memory_usage(&self) -> Result<usize, CelersError>
Estimate memory usage of tasks in all queues (in bytes)
This is an approximation based on serialized task sizes.
Sourcepub async fn bulk_replay_from_dlq(
&self,
max_count: Option<usize>,
) -> Result<usize, CelersError>
pub async fn bulk_replay_from_dlq( &self, max_count: Option<usize>, ) -> Result<usize, CelersError>
Move tasks from DLQ back to main queue in bulk
Returns the number of tasks moved.
Sourcepub async fn peek_next(&self) -> Result<Option<SerializedTask>, CelersError>
pub async fn peek_next(&self) -> Result<Option<SerializedTask>, CelersError>
Peek at the next task without dequeueing it
Useful for inspecting what will be processed next without removing it from the queue.
Sourcepub async fn queue_depth_percentage(
&self,
max_recommended_size: Option<usize>,
) -> Result<f64, CelersError>
pub async fn queue_depth_percentage( &self, max_recommended_size: Option<usize>, ) -> Result<f64, CelersError>
Get queue depth percentage (current size / max recommended size)
Returns a value between 0.0 and 1.0+ where > 0.8 suggests the queue is getting full. max_recommended_size defaults to 10000 if not specified.
Sourcepub async fn is_near_capacity(
&self,
max_recommended_size: Option<usize>,
) -> Result<bool, CelersError>
pub async fn is_near_capacity( &self, max_recommended_size: Option<usize>, ) -> Result<bool, CelersError>
Check if the queue is approaching capacity (> 80% of recommended max)