kv

package
v0.6.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	With  = contextx.With[tCtxExecutor, Executor]
	From  = contextx.From[tCtxExecutor, Executor]
	Must  = contextx.Must[tCtxExecutor, Executor]
	Carry = contextx.Carry[tCtxExecutor, Executor]
)

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Key returns cache key with given key.
	Key(string) string
	// Exec executes cache command
	Exec(context.Context, string, ...any) (any, error)
}

type Store added in v0.5.3

type Store interface {
	// Get returns the value for key.
	// The bool is false when the key does not exist.
	Get(ctx context.Context, key string) (string, bool, error)
	// Set writes key to val, overwriting any existing value.
	// ttl <= 0 means the key has no expiration.
	Set(ctx context.Context, key, val string, ttl time.Duration) error
	// SetNX writes key to val only if the key does not already exist.
	// ok is true when the key was set.
	// ttl <= 0 means the key has no expiration.
	SetNX(ctx context.Context, key, val string, ttl time.Duration) (ok bool, err error)
	// Del deletes key.
	// deleted is true when the key existed and was removed.
	// It is not an error if the key does not exist.
	Del(ctx context.Context, key string) (deleted bool, err error)
	// TTL returns the remaining time to live of key.
	//
	// Return cases (when err is nil):
	//  1. key does not exist:           ttl == 0, exists == false
	//  2. key exists, no expiration:    ttl == 0, exists == true
	//  3. key exists with expiration:   ttl > 0,  exists == true
	TTL(ctx context.Context, key string) (ttl time.Duration, exists bool, err error)
}

Store is a key-value store with optional TTL.

Jump to

Keyboard shortcuts

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