Documentation
¶
Overview ¶
Package kv provides the shared key/value client class used by the valkey and badgerdb plugins. Both plugins expose the identical surface — the only difference is the factory: valkey.connect(url) reaches a server over the network, badgerdb.open(path) opens an embedded store — so scripts can move between a distributed cache and local storage without changes.
Index ¶
- Constants
- func ClientClass(constructor interface{}, extras func(*object.ClassBuilder)) *object.ClassBuilder
- func FormatTTLError(op string, err error) error
- func GlobPrefix(pattern string) string
- func MatchGlob(pattern, key string) bool
- func TTLSeconds(remaining time.Duration) int64
- type Client
- type Store
Constants ¶
const TTLNoExpiry = int64(-1)
TTLNoExpiry is what ttl() reports for a key that exists but never expires (redis semantics: -1). A missing key reports null.
Variables ¶
This section is empty.
Functions ¶
func ClientClass ¶
func ClientClass(constructor interface{}, extras func(*object.ClassBuilder)) *object.ClassBuilder
ClientClass builds the shared class. constructor is the plugin-specific typed constructor (valkey's dials a server, badger's opens a directory); it must return (*Client, error). Scripts construct the class directly or through each plugin's connect()/open() helper. extras, when non-nil, registers backend-specific methods beyond the mirrored core (valkey's sets and queues); backends without those types pass nil and the mirror stays exact.
func FormatTTLError ¶
FormatTTLError normalises backend TTL probing for error messages.
func GlobPrefix ¶
GlobPrefix returns the literal prefix of a glob pattern (everything before the first wildcard character); backends use it to bound iteration.
func MatchGlob ¶
MatchGlob reports whether key matches a redis-style glob pattern using the host's path.Match syntax (*, ?, [class]) — the same wildcard language for both backends.
func TTLSeconds ¶
TTLSeconds converts a remaining-time duration to whole seconds, rounding up so a key that expires "now" still reports 1s rather than vanishing mid-report.
Types ¶
type Store ¶
type Store interface {
Get(ctx context.Context, key string) (string, bool, error)
Set(ctx context.Context, key, value string, ttlSeconds int64) error
Delete(ctx context.Context, keys []string) (int64, error)
Exists(ctx context.Context, keys []string) (int64, error)
Expire(ctx context.Context, key string, ttlSeconds int64) (bool, error)
Persist(ctx context.Context, key string) (bool, error)
TTL(ctx context.Context, key string) (int64, bool, error)
Incr(ctx context.Context, key string, amount int64) (int64, error)
Keys(ctx context.Context, pattern string) ([]string, error)
MGet(ctx context.Context, keys []string) ([]*string, error)
MSet(ctx context.Context, mapping map[string]string, ttlSeconds int64) error
SetNX(ctx context.Context, key, value string, ttlSeconds int64) (bool, error)
HashSet(ctx context.Context, key, field, value string) (int64, error)
HashGet(ctx context.Context, key, field string) (*string, error)
HashDelete(ctx context.Context, key string, fields []string) (int64, error)
HashAll(ctx context.Context, key string) (map[string]string, error)
HashSize(ctx context.Context, key string) (int64, error)
Ping(ctx context.Context) error
Close() error
}
Store is the backend contract both plugins implement.