store

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package store provides pubsub state backends for GoSPA.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found")

ErrNotFound is returned when a key is not found in the storage.

Functions

This section is empty.

Types

type MemoryPubSub

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

MemoryPubSub provides an in-memory implementation of the PubSub interface. It is intended for single-process environments where external infrastructure is not needed.

func NewMemoryPubSub

func NewMemoryPubSub() *MemoryPubSub

NewMemoryPubSub creates a new in-memory PubSub system.

func (*MemoryPubSub) Publish

func (p *MemoryPubSub) Publish(_ context.Context, channel string, message []byte) error

Publish sends a message to all subscribers of a channel.

func (*MemoryPubSub) Subscribe

func (p *MemoryPubSub) Subscribe(_ context.Context, channel string, handler func(message []byte)) (Unsubscribe, error)

Subscribe registers a handler and returns an Unsubscribe function.

type MemoryStorage

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

MemoryStorage provides an in-memory implementation of the Storage interface.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new in-memory storage.

func (*MemoryStorage) Close added in v0.1.13

func (s *MemoryStorage) Close() error

Close explicitly stops the background pruning loop to prevent goroutine leaks.

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(_ context.Context, key string) error

Delete removes a value from the in-memory store.

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(_ context.Context, key string) ([]byte, error)

Get retrieves a value from the in-memory store.

func (*MemoryStorage) Set

func (s *MemoryStorage) Set(_ context.Context, key string, val []byte, exp time.Duration) error

Set stores a value in the in-memory store.

type PubSub

type PubSub interface {
	Publish(ctx context.Context, channel string, message []byte) error
	Subscribe(ctx context.Context, channel string, handler func(message []byte)) (Unsubscribe, error)
}

PubSub represents an external publish-subscribe mechanism for multi-process broadcasting.

type Storage

type Storage interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, val []byte, exp time.Duration) error
	Delete(ctx context.Context, key string) error
}

Storage represents an external key-value store for session and state data.

type Unsubscribe added in v0.1.30

type Unsubscribe func()

Unsubscribe is a function to cancel a subscription.

Directories

Path Synopsis
Package redis provides a Redis-backed implementation of the store.Storage interface.
Package redis provides a Redis-backed implementation of the store.Storage interface.

Jump to

Keyboard shortcuts

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