keyspace

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package keyspace provides typed, namespaced key partitions for Grove KV.

A Keyspace[T] binds a key prefix, codec, and TTL policy to a Go type, providing type-safe Get/Set operations with automatic serialization.

users := keyspace.New[User](store, "users",
    keyspace.WithTTL(24 * time.Hour),
    keyspace.WithCodec(codec.MsgPack()),
)
user, err := users.Get(ctx, "u_12345")
err = users.Set(ctx, "u_12345", user)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposeKey

func ComposeKey(separator string, segments ...string) string

ComposeKey builds a composite key from segments joined by the given separator.

func Join

func Join(segments ...string) string

Join builds a composite key from segments using ":" as the separator.

func ParseKey

func ParseKey(key, separator string) []string

ParseKey splits a composite key into segments by the given separator.

Types

type Keyspace

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

Keyspace is a typed, namespaced partition of a KV store. All keys are automatically prefixed with the keyspace prefix + separator.

func New

func New[T any](store *kv.Store, prefix string, opts ...Option) *Keyspace[T]

New creates a new Keyspace bound to the given store and prefix.

func (*Keyspace[T]) Delete

func (ks *Keyspace[T]) Delete(ctx context.Context, keys ...string) error

Delete removes one or more keys within this keyspace.

func (*Keyspace[T]) Exists

func (ks *Keyspace[T]) Exists(ctx context.Context, keys ...string) (int64, error)

Exists returns the count of keys that exist within this keyspace.

func (*Keyspace[T]) Get

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

Get retrieves and decodes the value for the given key within this keyspace.

func (*Keyspace[T]) GetEntry

func (ks *Keyspace[T]) GetEntry(ctx context.Context, key string) (*kv.Entry[T], error)

GetEntry retrieves the value with full metadata (TTL, version, etc.).

func (*Keyspace[T]) MGet

func (ks *Keyspace[T]) MGet(ctx context.Context, keys []string) (map[string]T, error)

MGet retrieves multiple keys within this keyspace.

func (*Keyspace[T]) Prefix

func (ks *Keyspace[T]) Prefix() string

Prefix returns the keyspace prefix.

func (*Keyspace[T]) Scan

func (ks *Keyspace[T]) Scan(ctx context.Context, pattern string, fn func(key string) error) error

Scan iterates over keys within this keyspace matching the given pattern suffix.

func (*Keyspace[T]) Set

func (ks *Keyspace[T]) Set(ctx context.Context, key string, value T, opts ...kv.SetOption) error

Set encodes and stores the value under the given key within this keyspace.

func (*Keyspace[T]) Store

func (ks *Keyspace[T]) Store() *kv.Store

Store returns the underlying store.

type Option

type Option func(*config)

Option configures a Keyspace.

func WithCodec

func WithCodec(cc codec.Codec) Option

WithCodec sets the codec used for serialization within the keyspace. This overrides the store-level codec.

func WithSeparator

func WithSeparator(sep string) Option

WithSeparator sets the key segment separator (default ":").

func WithTTL

func WithTTL(d time.Duration) Option

WithTTL sets the default TTL for all Set operations in the keyspace.

Jump to

Keyboard shortcuts

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