kv

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key       string
	Value     json.RawMessage
	ExpiresAt *time.Time
	CreatedAt time.Time
	UpdatedAt time.Time
}

Entry represents a raw KV entry with metadata.

type KV

type KV interface {
	Get(ctx context.Context, key string, dest any) error
	Set(ctx context.Context, key string, value any) error
	SetTTL(ctx context.Context, key string, value any, ttl time.Duration) error
	Delete(ctx context.Context, key string) error
	Has(ctx context.Context, key string) (bool, error)
	ListKeys(ctx context.Context) ([]string, error)
	GetRaw(ctx context.Context, key string) (Entry, error)
}

KV is the interface for a persistent key-value store. Keys are strings, values are JSON-serializable. Get on a missing key returns an error wrapping sql.ErrNoRows.

type TypedKV

type TypedKV[T any] struct {
	// contains filtered or unexported fields
}

TypedKV provides type-safe access to a KV store for a specific type T.

func Scoped

func Scoped[T any](store KV, namespace string) *TypedKV[T]

Scoped returns a TypedKV[T] that prefixes all keys with "namespace:".

func (*TypedKV[T]) Delete

func (t *TypedKV[T]) Delete(ctx context.Context, key string) error

Delete removes a key.

func (*TypedKV[T]) Get

func (t *TypedKV[T]) Get(ctx context.Context, key string) (T, error)

Get retrieves and deserializes a value by key.

func (*TypedKV[T]) Has

func (t *TypedKV[T]) Has(ctx context.Context, key string) (bool, error)

Has returns whether a key exists.

func (*TypedKV[T]) Set

func (t *TypedKV[T]) Set(ctx context.Context, key string, value T) error

Set stores a value with no expiry.

func (*TypedKV[T]) SetTTL

func (t *TypedKV[T]) SetTTL(ctx context.Context, key string, value T, ttl time.Duration) error

SetTTL stores a value that expires after the given duration.

Jump to

Keyboard shortcuts

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