replaybuffer

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package replaybuffer builds a ReplayBuffer from config — the in-process memory buffer (single pod; the default) or Redis (cross-pod) — and runs it through the client tier (Decorate). Callers depend on core/interfaces.ReplayBuffer, so swapping one backend for the other is a config change, never a logic edit. The concrete backends live in the memory/ and redis/ subpackages.

Index

Constants

View Source
const (
	// KindMemory keeps each key's tail in process: correct for a single pod (the
	// default).
	KindMemory client.Kind = "memory"

	// KindRedis keeps each key's tail in Redis, shared across pods.
	KindRedis client.Kind = "redis"
)

Variables

This section is empty.

Functions

func Decorate added in v0.0.7

func Decorate(
	base interfaces.ReplayBuffer,
	name string,
	deps decorate.Deps,
) interfaces.ReplayBuffer

Decorate runs every operation of base through the client tier as the client named name.

func NewFromConfig

func NewFromConfig(
	ctx context.Context,
	cfg Config,
	deps Deps,
) (interfaces.ReplayBuffer, error)

NewFromConfig builds the replay buffer cfg.Kind selects and runs it through the client tier. A non-positive MaxSize or TTL, an unknown kind, or KindRedis without Deps.Redis is CodeInvalidInput.

Types

type Config

type Config struct {
	// Kind selects the backend; empty means KindMemory.
	Kind client.Kind `yaml:"kind" mapstructure:"kind"`

	// KeyPrefix namespaces the redis backend's keys (empty uses
	// redis.DefaultKeyPrefix, "replay:"); ignored for KindMemory.
	KeyPrefix string `yaml:"key_prefix" mapstructure:"key_prefix"`

	// Name labels the client in decoration overrides, metrics, spans and logs; empty
	// uses the family name ("replaybuffer").
	Name string `yaml:"name" mapstructure:"name"`

	// MaxSize bounds the retained messages per key.
	MaxSize int `yaml:"max_size" mapstructure:"max_size"`

	// TTL is how long a key's buffer lives after its last Append.
	TTL time.Duration `yaml:"ttl" mapstructure:"ttl"`
}

Config selects and tunes the replay buffer.

type Deps added in v0.0.7

type Deps struct {
	// Decorations decorates the client from the decoration config (decoration.clients)
	// and supplies its observability.
	decorate.Decorations

	// Redis is the shared go-redis client KindRedis requires.
	Redis *goredis.Client
}

Deps carries the replay buffer's runtime collaborators.

Directories

Path Synopsis
Package memory provides an in-process ReplayBuffer backend for single-pod deployments (dev / replica=1), where a reconnect lands on the same pod so cross-pod sharing is unnecessary.
Package memory provides an in-process ReplayBuffer backend for single-pod deployments (dev / replica=1), where a reconnect lands on the same pod so cross-pod sharing is unnecessary.
Package redis provides a cross-pod ReplayBuffer backend over Redis, for multi-replica deployments (staging/prod) where a reconnect may land on a different pod than the one that buffered the tail.
Package redis provides a cross-pod ReplayBuffer backend over Redis, for multi-replica deployments (staging/prod) where a reconnect may land on a different pod than the one that buffered the tail.

Jump to

Keyboard shortcuts

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