Documentation
¶
Index ¶
- Constants
- type Entry
- type Option
- type SQLiteStore
- func (s *SQLiteStore) Cleanup(ctx context.Context) error
- func (s *SQLiteStore) Close() error
- func (s *SQLiteStore) Delete(ctx context.Context, agent, key string) error
- func (s *SQLiteStore) Get(ctx context.Context, agent, key string) (string, bool, error)
- func (s *SQLiteStore) List(ctx context.Context, agent, prefix string) ([]Entry, error)
- func (s *SQLiteStore) Set(ctx context.Context, agent, key, value string, ttl time.Duration) error
- func (s *SQLiteStore) SetNX(ctx context.Context, agent, key, value string, ttl time.Duration) (bool, error)
- type Store
Constants ¶
const MaxKeysPerAgent = 1000
MaxKeysPerAgent is the default maximum number of keys per agent.
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 ¶
WithMaxKeysPerAgent sets the maximum number of keys per agent (0 = unlimited).
func WithMaxValueBytes ¶
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 ¶
Get returns the value for a key, or ("", false, nil) if not found or expired.
func (*SQLiteStore) List ¶
List returns all non-expired keys for an agent, optionally filtered by prefix.
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.