kv

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const MaxKeysPerAgent = 1000

MaxKeysPerAgent is the default maximum number of keys per agent.

View Source
const MaxValueBytes = 65536

MaxValueBytes is the default maximum value size in bytes (64 KB).

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Key       string     `db:"key"`
	Value     string     `db:"value"`
	CreatedAt time.Time  `db:"created_at"`
	UpdatedAt time.Time  `db:"updated_at"`
	ExpiresAt *time.Time `db:"expires_at"`
}

Entry represents a key-value pair with metadata.

type Option

type Option func(*SQLiteStore)

Option configures a SQLiteStore.

func WithMaxKeysPerAgent

func WithMaxKeysPerAgent(n int) Option

WithMaxKeysPerAgent sets the maximum number of keys per agent (0 = unlimited).

func WithMaxValueBytes

func WithMaxValueBytes(n int) Option

WithMaxValueBytes sets the maximum value size in bytes.

type SQLiteStore

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

SQLiteStore implements Store using SQLite.

func NewInMemoryStore

func NewInMemoryStore(opts ...Option) (*SQLiteStore, error)

NewInMemoryStore creates an in-memory SQLite store for testing.

func NewSQLiteStore

func NewSQLiteStore(dbPath string, opts ...Option) (*SQLiteStore, error)

NewSQLiteStore opens or creates a SQLite database and applies the KV schema.

func (*SQLiteStore) Cleanup

func (s *SQLiteStore) Cleanup(ctx context.Context) error

Cleanup removes all expired keys.

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close releases the database connection.

func (*SQLiteStore) Delete

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

Delete removes a key. No error if the key does not exist.

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, agent, key string) (string, bool, error)

Get returns the value for a key, or ("", false, nil) if not found or expired.

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, agent, prefix string) ([]Entry, error)

List returns all non-expired keys for an agent, optionally filtered by prefix.

func (*SQLiteStore) Set

func (s *SQLiteStore) Set(ctx context.Context, agent, key, value string, ttl time.Duration) error

Set stores a key-value pair. If ttl is zero, the key does not expire.

func (*SQLiteStore) SetNX

func (s *SQLiteStore) SetNX(ctx context.Context, agent, key, value string, ttl time.Duration) (bool, error)

SetNX stores a key only if it doesn't already exist (atomic). Returns true if the key was set, false if it already existed (and is not expired).

type Store

type Store interface {
	Get(ctx context.Context, agent, key string) (value string, ok bool, err error)
	Set(ctx context.Context, agent, key, value string, ttl time.Duration) error
	Delete(ctx context.Context, agent, key string) error
	List(ctx context.Context, agent, prefix string) ([]Entry, error)
	SetNX(ctx context.Context, agent, key, value string, ttl time.Duration) (bool, error)
	Cleanup(ctx context.Context) error
	Close() error
}

Store provides per-agent key-value storage with optional TTL.

Jump to

Keyboard shortcuts

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