redisstreams

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 8 Imported by: 0 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 redisstreams is RunStreams over Redis Streams, shared by the Redis and Upstash adapters. Each stream is two keys in one hash slot: a hash with who it belongs to, whether it is closed and its end event, and the Redis Stream itself, one entry per event. The offset is the entry id. Every write is one Lua script, so a close can never slip between an append's check and its XADD. The TS adapters run the same scripts on the same keys (src/adapters/stream-scripts.ts).

Index

Constants

View Source
const AppendScript = `` /* 323-byte string literal not displayed */

AppendScript: KEYS meta, stream. ARGV one event JSON each. The entry ids, or -1 gone, -2 closed. The stream key takes the meta key's expiry.

View Source
const CloseScript = `` /* 315-byte string literal not displayed */

CloseScript: KEYS meta, stream. ARGV end JSON, graceMs. 1 closed, 0 already closed, -1 gone.

View Source
const DeleteScript = `redis.call('DEL', KEYS[1], KEYS[2]) return 1`

DeleteScript: KEYS meta, stream.

View Source
const OpenScript = `` /* 186-byte string literal not displayed */

OpenScript: KEYS meta, stream. ARGV threadId, runId, ttlMs. 1 opened, 0 already open.

View Source
const ReadScript = `` /* 210-byte string literal not displayed */

ReadScript: KEYS meta, stream. ARGV the XRANGE start ('-', or '(' + an entry id). -1 gone, else { threadId, runId, closed, the end JSON or an empty string, entries }.

Variables

This section is empty.

Functions

func CompareIDs

func CompareIDs(a, b string) int

CompareIDs compares two entry ids ("<ms>-<seq>").

func Key

func Key(streamID string) string

Key is the Redis Stream itself.

func MetaKey

func MetaKey(streamID string) string

MetaKey is a stream's hash.

func Sleep

func Sleep(ctx context.Context, d time.Duration)

Sleep waits d, or until ctx is done: the wait of a store with no blocking read.

Types

type RunScript

type RunScript func(ctx context.Context, script string, keys []string, args []any) (any, error)

RunScript runs a script: the one thing the Redis and Upstash clients differ in. The reply uses Go's plain types: string, int64 (or a JSON number), []any.

type Streams

type Streams struct {
	Run  RunScript
	Wait WaitForNews
	// Poll is the longest a reader waits before reading again, news or
	// not: the floor under a missed wake-up.
	Poll time.Duration
}

Streams implements ports.RunStreams over the scripts.

func (*Streams) Append

func (s *Streams) Append(ctx context.Context, streamID string, events []ports.StreamEvent) ([]string, error)

func (*Streams) Close

func (s *Streams) Close(ctx context.Context, streamID string, end ports.StreamEnd, grace time.Duration) error

func (*Streams) Delete

func (s *Streams) Delete(ctx context.Context, streamID string) error

func (*Streams) Open

func (s *Streams) Open(ctx context.Context, streamID string, meta ports.StreamMeta, ttl time.Duration) error

func (*Streams) Read

func (s *Streams) Read(ctx context.Context, streamID, after string) iter.Seq2[ports.StreamItem, error]

func (*Streams) Snapshot

func (s *Streams) Snapshot(ctx context.Context, streamID, after string) (*ports.StreamSnapshot, error)

type WaitForNews

type WaitForNews func(ctx context.Context, key, after string, max time.Duration)

WaitForNews waits until the stream key may have an entry past `after`, or max passes, or ctx is done. Returning early without news is harmless: the reader reads again and finds nothing.

Jump to

Keyboard shortcuts

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