redis

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package redis provides a durable queue.Service backed by Redis.

Data layout (per topic) — keys use Redis hash tags so all per-topic state hashes to the same slot in Redis Cluster:

queue:{<topic>}:ready    Sorted Set, score = -priority * 1e13 + run_at_ms
queue:{<topic>}:inflight Sorted Set, score = locked_until_ms
queue:{<topic>}:job:<id> Hash with fields: payload, priority, attempt,
                         enqueued_at, last_error
queue:{<topic>}:notify   List used with BLPOP for push wake-up

All single-topic operations (enqueue, claim, ack, fail, reap) are Lua scripts so multi-key updates are atomic from Redis's perspective. Dead letter routing crosses topics and is therefore split into two Go-side scripts (enqueue into DLQ, then ack source); a failure between the two produces an at-least-once DLQ delivery, which matches the package's overall delivery contract.

A reaper goroutine periodically scans inflight for entries whose lease has expired and moves them back to ready.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the Redis queue implementation.

func New

func New(ctx context.Context, client rds.UniversalClient, opts ...queue.QueueOption) (*Service, error)

New constructs a Redis queue service. The caller owns client.

func (*Service) Close

func (s *Service) Close(_ context.Context) error

Close closes all consumers.

func (*Service) Enqueue

func (s *Service) Enqueue(ctx context.Context, topicName string, payload []byte, opts ...queue.EnqueueOption) error

Enqueue runs the enqueue Lua script.

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, topicName string, h queue.Handler, opts ...queue.SubscribeOption) (queue.Consumer, error)

Subscribe spawns a worker pool and a reaper goroutine.

Jump to

Keyboard shortcuts

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