Documentation
¶
Overview ¶
Package redisqueue provides a Redis-backed queue.Driver, queue.BulkPusher, and queue.Sizer using github.com/redis/go-redis/v9.
Applications automatically receive a *Driver for every connection in config.Queue.Connections whose Driver is "redis". To construct one directly:
driver := redisqueue.New(client, 5*time.Second)
Each queue stores its data under keys that share the queue name as a hash tag so Redis Cluster keeps all keys for a queue on the same slot:
queues:{name} list of available job IDs in FIFO order
queues:{name}:delayed sorted set of delayed job IDs scored by due time
queues:{name}:reserved sorted set of reserved job IDs scored by lease expiry
queues:{name}:payloads hash mapping job ID to raw payload
queues:{name}:attempts hash mapping job ID to reservation count
queues:{name}:notify list of notification tokens for blocking workers
Index ¶
- type Driver
- func (d *Driver) Clear(ctx context.Context, queue string) (int64, error)
- func (d *Driver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error
- func (d *Driver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error
- func (d *Driver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)
- func (d *Driver) Sizes(ctx context.Context, name string) (queue.Sizes, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is a Redis-backed queue.Driver, queue.BulkPusher, and queue.Sizer. Multiple workers can share a queue safely, and Lua scripts guarantee that each job is reserved by only one worker at a time.
func New ¶
func New(client redis.UniversalClient, blockFor time.Duration) *Driver
New returns a *Driver backed by client. The caller remains responsible for closing client.
When blockFor is positive, Driver.Reserve blocks on Redis for up to blockFor (in whole seconds) when no job is immediately available, waking as soon as a job is pushed. Enable ContextTimeoutEnabled on client so stopping a worker cancels a blocking wait promptly. Redis Cluster clients are supported when each blocking worker polls a single queue, because a queue's keys share one hash slot.
func (*Driver) Clear ¶
Clear deletes all Redis keys for queue and returns the number of jobs that were pending, delayed, or reserved.
func (*Driver) PushBulk ¶
PushBulk stores payloads on queue in batches so they are immediately available to workers.
func (*Driver) Reserve ¶
Reserve claims the next available job from the first non-empty queue in queues, migrating due delayed jobs and expired reservations first. If no job is available and blockFor is positive, Reserve blocks on the queues' notify lists until a job arrives, blockFor elapses, or ctx is canceled.