upstash

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 10 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 upstash holds the reference Kv and EventBus adapters over the Upstash Redis REST API.

Upstash Pub/Sub over REST has no subscribe: live tailing needs a WebSocket-based subscriber, which differs per SDK. Wire one in through the Subscriber interface; replay-only usage works without it.

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.

Types

type Bus

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

Bus is an EventBus over Upstash Redis REST publish plus an optional subscriber.

func NewBus

func NewBus(redis *Redis, subscriber Subscriber) *Bus

NewBus wraps a client. subscriber may be nil for replay-only usage.

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 Upstash Redis REST.

func NewKv

func NewKv(redis *Redis) *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 Redis

type Redis struct {
	// URL is UPSTASH_REDIS_REST_URL.
	URL string
	// Token is UPSTASH_REDIS_REST_TOKEN.
	Token string
	// HTTP defaults to http.DefaultClient.
	HTTP *http.Client
}

Redis is the Upstash Redis REST client the adapters use.

func (*Redis) Do

func (r *Redis) Do(ctx context.Context, cmd ...any) (json.RawMessage, error)

Do runs one command and returns its result.

type RunStreams added in v0.4.0

type RunStreams struct{ *redisstreams.Streams }

RunStreams is RunStreams over Upstash Redis Streams: the same keys and scripts as the Redis adapter (see package redisstreams). Upstash's REST API has no blocking read, so a live reader polls every Poll.

func NewRunStreams added in v0.4.0

func NewRunStreams(redis *Redis, poll time.Duration) *RunStreams

NewRunStreams wraps a client. A zero poll means 250ms.

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, threadID string, handler func(raw string)) (func() error, error)
}

Subscriber tails a thread channel. Return an unsubscribe function.

Jump to

Keyboard shortcuts

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