rediskit

package
v0.5.1 Latest Latest
Warning

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

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

Documentation

Overview

Package rediskit provides reusable Redis primitives shared across services.

It intentionally stays below business adapters and key schemas: callers bring their own Redis clients, naming conventions, TTL policies, and repositories. The package only offers low-level helpers such as keyspace prefixing, TTL jitter, batched scan/delete, lease locks, and single-key atomic consume.

For pattern deletion, callers should prefer DefaultDeleteByPatternOptions() instead of assembling their own zero-value option struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireLease

func AcquireLease(ctx context.Context, client goredis.UniversalClient, key string, ttl time.Duration) (string, bool, error)

AcquireLease tries to acquire a leased lock using SET NX EX semantics.

func ConsumeIfExists

func ConsumeIfExists(ctx context.Context, client goredis.UniversalClient, key string) (bool, error)

ConsumeIfExists atomically checks and deletes a single key.

func DeleteByPattern

func DeleteByPattern(ctx context.Context, client goredis.UniversalClient, pattern string, opts DeleteByPatternOptions) (int, error)

DeleteByPattern scans and deletes keys in batches.

func JitterTTL

func JitterTTL(ttl time.Duration, ratio float64) time.Duration

JitterTTL adds symmetric jitter around the input TTL using the provided ratio.

func NormalizeNamespace

func NormalizeNamespace(ns string) string

NormalizeNamespace trims trailing/leading separators from a Redis namespace.

func ReleaseLease

func ReleaseLease(ctx context.Context, client goredis.UniversalClient, key, token string) error

ReleaseLease releases a lock only when the lease token matches.

func ScanKeys

func ScanKeys(ctx context.Context, client goredis.UniversalClient, pattern string, count int64) ([]string, error)

ScanKeys collects keys using SCAN for the provided pattern.

Types

type DeleteByPatternOptions

type DeleteByPatternOptions struct {
	ScanCount int64
	BatchSize int
	UseUnlink bool
}

DeleteByPatternOptions controls batched key deletion.

func DefaultDeleteByPatternOptions

func DefaultDeleteByPatternOptions() DeleteByPatternOptions

DefaultDeleteByPatternOptions returns the canonical pattern-deletion defaults.

type Keyspace

type Keyspace struct {
	Namespace string
}

Keyspace prefixes raw Redis keys with an optional namespace.

func NewKeyspace

func NewKeyspace(namespace string) Keyspace

NewKeyspace creates a namespaced keyspace helper.

func (Keyspace) Child added in v0.4.8

func (k Keyspace) Child(child string) Keyspace

Child returns a nested keyspace under the current namespace.

func (Keyspace) Prefix

func (k Keyspace) Prefix(key string) string

Prefix returns the key with namespace applied when configured.

Jump to

Keyboard shortcuts

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