cache

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch added in v1.12.0

type Batch interface {
	// MGetBytes fetches multiple string keys in a single MGET round-trip.
	// Returns one []byte per key; nil entries mean key-not-found.
	MGetBytes(ctx context.Context, keys ...string) ([][]byte, error)
}

type Cache

type Cache interface {
	KV
	JSON
	Locker
	Hash
	Batch
	SortedSet
	Stream
}

type Hash added in v1.12.0

type Hash interface {
	HGet(ctx context.Context, key, field string) (string, error)
	HSet(ctx context.Context, key, field, value string) error
	HDel(ctx context.Context, key, field string) error
	HGetAll(ctx context.Context, key string) (map[string]string, error)
	// HGetAllMulti pipelines multiple HGETALL commands in one round-trip.
	// Returns one map per key in the same order; nil maps mean the key was empty/missing.
	HGetAllMulti(ctx context.Context, keys []string) ([]map[string]string, error)
	HIncrBy(ctx context.Context, key, field string, delta int64) (int64, error)
}

type JSON added in v1.12.0

type JSON interface {
	SetJSON(ctx context.Context, key string, val interface{}) error
	SetTimedJSON(ctx context.Context, key string, val interface{}, ttl int64, opts ...TimedOption) error
	// SetTimedJSONNX marshals val and sets it only if the key does not already exist (SET NX).
	// Returns true if the key was set, false if it already existed.
	SetTimedJSONNX(ctx context.Context, key string, val interface{}, ttl int64, opts ...TimedOption) (bool, error)
	GetJSON(ctx context.Context, key string, v interface{}) error
	GetJSONWithTTL(ctx context.Context, key string, v interface{}) (LookupMeta, error)
	// SetTimedJSONBatch pipelines multiple timed JSON SET commands in one round-trip.
	// keys[i] is the Redis key for vals[i].
	SetTimedJSONBatch(ctx context.Context, keys []string, vals []interface{}, ttl int64, opts ...TimedOption) error
}

type KV added in v1.12.0

type KV interface {
	Set(ctx context.Context, key, val string) error
	Get(ctx context.Context, key string) (string, error)
	GetWithTTL(ctx context.Context, key string) (string, LookupMeta, error)
	Delete(ctx context.Context, key string) error
	GetBytes(ctx context.Context, key string) ([]byte, error)
	SetTimed(ctx context.Context, key, val string, ttl int64) error
	SetTimedInt64(ctx context.Context, key string, val int64, ttl int64) error
	SetInt64(ctx context.Context, key string, val int64) error
	SetTTL(ctx context.Context, key string, ttl int64) error
	Incr(ctx context.Context, key string) (int64, error)
	GetInt64(ctx context.Context, key string) (int64, error)
}

type Locker added in v1.12.0

type Locker interface {
	TryAcquireRefreshLock(ctx context.Context, key, token string, ttl time.Duration) (bool, error)
	ReleaseRefreshLock(ctx context.Context, key, token string) error
}

type LookupMeta added in v1.12.0

type LookupMeta struct {
	Hit    bool
	TTL    time.Duration
	HasTTL bool
}

LookupMeta describes a cache lookup result.

type SortedSet added in v1.12.0

type SortedSet interface {
	// ZAddBatch adds multiple members to a sorted set in a single ZADD command.
	ZAddBatch(ctx context.Context, key string, members []ZBatchMember) error
	ZAdd(ctx context.Context, key string, score float64, member string) error
	ZRem(ctx context.Context, key string, members ...string) error
	ZRevRangeByScore(ctx context.Context, key, max, min string, offset, count int64) ([]string, error)
}

type Stream added in v1.12.0

type Stream interface {
	XAdd(ctx context.Context, stream string, maxLen int64, approx bool, values map[string]interface{}) error
}

type TimedOption added in v1.12.0

type TimedOption interface {
	// contains filtered or unexported methods
}

func NoneProactive added in v1.12.0

func NoneProactive() TimedOption

type TimedOptions added in v1.12.0

type TimedOptions struct {
	Proactive bool
}

func DefaultTimedOptions added in v1.12.0

func DefaultTimedOptions() TimedOptions

func ResolveTimedOptions added in v1.12.0

func ResolveTimedOptions(opts ...TimedOption) TimedOptions

type ZBatchMember added in v1.10.0

type ZBatchMember struct {
	Score  float64
	Member string
}

ZBatchMember is a (score, member) pair for ZAddBatch.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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