redis

package
v0.32.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package redis provides a Redis-backed implementation of ports/kv.Store and an ES es.Snapshotter built on top of it.

Usage:

client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
snapshotter, err := clstrredis.NewSnapshotter(clstrredis.Config{
    Client:    client,
    KeyPrefix: "myapp:account-123",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSnapshotter

func NewSnapshotter(cfg Config) (*es.KeyValueSnapshotter, error)

NewSnapshotter creates an ES snapshotter backed by Redis. It wraps a KvStore in es.NewKeyValueSnapshotter, providing the same interface as the NATS-backed snapshotter but storing snapshots in Redis instead of NATS JetStream KV — reducing JetStream load under high concurrency.

func NewTestClient

func NewTestClient(t Testing) *redis.Client

NewTestClient spins up a redis:7-alpine testcontainer and returns a connected *redis.Client. The container is terminated automatically via t.Cleanup.

Types

type Config

type Config struct {
	// Client is the Redis client to use. Required.
	Client *redis.Client

	// KeyPrefix is an optional namespace prefix prepended to every key as
	// "{prefix}:{key}". Use it to isolate stores sharing the same Redis
	// instance, e.g. "acd-snapshots:account-abc123".
	KeyPrefix string
}

Config holds the configuration for a Redis-backed KV store.

type KvStore

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

KvStore implements kv.Store backed by Redis.

func NewKvStore

func NewKvStore(cfg Config) (*KvStore, error)

NewKvStore creates a new Redis-backed KV store from cfg. Returns an error if cfg.Client is nil.

func (*KvStore) Delete

func (s *KvStore) Delete(ctx context.Context, key string) error

Delete removes the key. It is not an error if the key does not exist.

func (*KvStore) Get

func (s *KvStore) Get(ctx context.Context, key string) (kv.Entry, error)

Get retrieves the entry stored under key. Returns kv.ErrNotFound when the key does not exist or has expired.

func (*KvStore) Put

func (s *KvStore) Put(ctx context.Context, key string, entry kv.Entry, opts kv.PutOptions) error

Put stores entry under key. When opts.TTL > 0 the key expires after that duration; TTL == 0 means the key persists indefinitely.

type Testing

type Testing interface {
	require.TestingT
	Context() context.Context
	Logf(format string, args ...any)
	Cleanup(func())
}

Testing is the subset of *testing.T required by test helpers in this package. It mirrors the interface used in adapters/nats.

Jump to

Keyboard shortcuts

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