RedisStorageDriver class
Production-ready Redis queue driver
Uses Redis for distributed, persistent job queuing. Perfect for:
- Production applications
- Distributed systems
- High-volume workloads
- Multiple workers
- Jobs that must survive crashes
Features:
- Persistent storage in Redis
- Distributed queue access
- Delayed jobs using sorted sets
- Atomic operations
- Connection pooling
- Health checks
- Full metrics tracking
- Middleware support
- Dead letter queue integration
Redis Data Structures:
queue:{name}- Main queue (list)queue:{name}:delayed- Delayed jobs (sorted set)queue:{name}:processing- Processing jobs (hash)
Example:
// Register serializable jobs
QueueJobRegistry.register('SendEmailJob',
(json) => SendEmailJob.fromJson(json));
final driver = RedisStorageDriver(
config: DriverConfig(
name: 'redis',
driverSpecificConfig: {
'host': 'localhost',
'port': 6379,
'password': 'secret',
'queueName': 'jobs',
},
),
metrics: metrics,
dlqHandler: dlqHandler,
);
await driver.push(SendEmailJob('user@example.com'));
await driver.process();
- Inheritance
-
- Object
- BaseQueueDriver
- RedisStorageDriver
Constructors
- RedisStorageDriver({required DriverConfig config, QueueMetrics? metrics, FailedJobHandler? dlqHandler, QueueMiddlewarePipeline? middleware, String? host, int? port, String? password, String? queueName})
Properties
- config → DriverConfig
-
finalinherited
- dlqHandler → FailedJobHandler?
-
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- host → String
-
final
- metrics → QueueMetrics?
-
finalinherited
- middleware → QueueMiddlewarePipeline?
-
finalinherited
- password → String?
-
final
- port → int
-
final
- queueName → String
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → Future< void> -
Clear all jobs (for testing)
override
-
createJobContext(
QueueJob job, {Duration? delay}) → JobContext -
Create job context
inherited
-
dispose(
) → Future< void> -
Dispose resources
override
-
executeJob(
JobContext context) → Future< void> -
Execute job with full lifecycle
inherited
-
generateJobId(
) → String -
Generate unique job ID
inherited
-
getStats(
) → Future< Map< String, dynamic> > -
Get driver statistics
override
-
handleJobFailure(
JobContext context) → Future< void> -
Handle job failure with retry logic
inherited
-
isHealthy(
) → Future< bool> -
Health check
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onJobCompleted(
JobContext context) → Future< void> -
Called when a job is successfully completed
inherited
-
onJobFailed(
JobContext context) → Future< void> -
Called when a job fails permanently
override
-
onJobRetried(
JobContext context) → Future< void> -
Called when a job is retried
inherited
-
process(
) → Future< void> -
Starts processing queued jobs.
override
-
push(
QueueJob job, {Duration? delay}) → Future< void> -
Pushes a QueueJob to the queue with optional
delay.override -
retryJob(
JobContext context, {required Duration delay}) → Future< void> -
Retry a failed job
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited