redis

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 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 redis holds the reference Kv and EventBus adapters over Redis (github.com/redis/go-redis/v9). Works against any Redis: local Docker, self-hosted, or managed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ThreadChannel

func ThreadChannel(threadID string) string

ThreadChannel is the pub/sub channel for a thread's events. Shared with the Upstash adapter and the TypeScript package.

Types

type Bus

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

Bus is an EventBus over Redis Pub/Sub.

One subscriber connection per process, shared by every subscription: a channel is subscribed when its first handler arrives and unsubscribed when its last one leaves. A connection per viewer would run a busy deployment into Redis's maxclients. Each subscription has its own queue and goroutine, so one slow handler holds up nobody else, and go-redis's own buffer never fills and drops.

While subscribed, a bus-only HEARTBEAT notice (seq 0, never persisted) reaches every subscription each heartbeat interval, from one ticker per process: the §2.5 watchdog pattern. Pub/sub is at-most-once, so a distributor treats heartbeats as a trigger to re-check for orphaned HITL waits, and a follower fills any gap from the log.

func NewBus

func NewBus(client goredis.UniversalClient, heartbeat time.Duration) *Bus

NewBus wraps a client. A zero heartbeat means one minute.

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, threadID string, event ports.AgentEvent) error

func (*Bus) Subscribe

func (b *Bus) Subscribe(ctx context.Context, threadID string, handler func(ports.AgentEvent)) (func() error, error)

type Kv

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

Kv is a Kv over Redis.

func NewKv

func NewKv(client goredis.UniversalClient) *Kv

NewKv wraps a client.

func (*Kv) Del

func (k *Kv) Del(ctx context.Context, key string) error

func (*Kv) DelIfValue added in v0.3.0

func (k *Kv) DelIfValue(ctx context.Context, key, expected string) (bool, error)

func (*Kv) Get

func (k *Kv) Get(ctx context.Context, key string) (string, bool, error)

func (*Kv) Incr

func (k *Kv) Incr(ctx context.Context, key string) (int64, error)

func (*Kv) IncrWithExpiry added in v0.3.0

func (k *Kv) IncrWithExpiry(ctx context.Context, key string, ttl time.Duration) (int64, error)

func (*Kv) Set

func (k *Kv) Set(ctx context.Context, key, value string, opts ports.SetOptions) (bool, error)

func (*Kv) SetIfValue added in v0.3.0

func (k *Kv) SetIfValue(ctx context.Context, key, expected, value string, ttl time.Duration) (bool, error)

type RunStreams added in v0.4.0

type RunStreams struct {
	*redisstreams.Streams
	// contains filtered or unexported fields
}

RunStreams is RunStreams over Redis Streams (see package redisstreams for the keys and scripts, the same ones the TS adapter runs). Readers in one process share one blocking XREAD; Poll is the floor under a missed wake-up.

The shared XREAD names many stream keys at once, so on Redis Cluster, where they live in different slots, it fails and readers poll instead.

func NewRunStreams added in v0.4.0

func NewRunStreams(client goredis.UniversalClient, opts StreamsOptions) *RunStreams

NewRunStreams wraps a client.

func (*RunStreams) Shutdown added in v0.4.0

func (r *RunStreams) Shutdown() error

Shutdown closes the shared tail connection.

type StreamsOptions added in v0.4.0

type StreamsOptions struct {
	// Poll is the longest a reader waits without news. Default 1s.
	Poll time.Duration
	// Block is how long the shared XREAD blocks per pass. Default 5s.
	Block time.Duration
}

StreamsOptions tunes NewRunStreams. Zero values take the defaults.

Jump to

Keyboard shortcuts

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