redis

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package redis provides a distributed stream.Service backed by Redis Streams.

The caller owns the *redis.Client (or redis.UniversalClient); this package never opens or closes the connection.

Maps each stream concept to native Redis Streams commands:

  • Publish → XADD stream MAXLEN ~ N * payload ... h:... ...
  • Subscribe → XGROUP CREATE on first call, then per-worker XREADGROUP loops with BLOCK for low-latency wake-up
  • Reclaim → XAUTOCLAIM with min-idle = VisibilityTimeout
  • Ack → XACK
  • DLQ routing → XADD to <stream>.dead followed by XACK on the source

MaxLen trim is reasserted on every publish via MAXLEN ~. MaxAge trim runs as part of the publish path via XTRIM MINID.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("stream/redis: service closed")

ErrClosed is returned by Publish or Subscribe after Close.

Functions

This section is empty.

Types

type Service

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

Service is the Redis Streams stream.Service implementation.

func New

func New(client rds.UniversalClient, opts ...stream.ServiceOption) *Service

New constructs a stream/redis Service. The caller owns client.

func (*Service) Close

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

Close drains all consumers. Idempotent. ctx bounds the overall close: cancellation aborts before the next consumer is drained and returns ctx.Err() — already-drained consumers stay drained.

func (*Service) Publish

func (s *Service) Publish(ctx context.Context, name string, payload []byte, opts ...stream.PublishOption) error

Publish sends a message via XADD. The payload is stored under the "payload" field; headers are stored as additional fields with "h:" prefix. MaxLen is applied as XADD MAXLEN ~ (approximate trimming for speed). MaxAge is applied via XTRIM MINID after the publish.

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, name, group string, h stream.Handler, opts ...stream.SubscribeOption) (stream.Consumer, error)

Jump to

Keyboard shortcuts

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