redisqueue

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func (d *Driver) Clear(ctx context.Context, queue string) (int64, error)

Clear deletes all Redis keys for queue and returns the number of jobs that were pending, delayed, or reserved.

func (*Driver) Push

func (d *Driver) Push(ctx context.Context, queue string, payload []byte, delay time.Duration) error

Push stores payload on queue in Redis so it becomes available after delay.

func (*Driver) PushBulk

func (d *Driver) PushBulk(ctx context.Context, queue string, payloads [][]byte) error

PushBulk stores payloads on queue in batches so they are immediately available to workers.

func (*Driver) Reserve

func (d *Driver) Reserve(ctx context.Context, queues []string) (queue.Reserved, error)

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.

func (*Driver) Sizes

func (d *Driver) Sizes(ctx context.Context, name string) (queue.Sizes, error)

Sizes returns the pending, delayed, and reserved job counts for name, along with the dispatch timestamp of the oldest pending job when available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL