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 ¶
- func AcquireLease(ctx context.Context, client goredis.UniversalClient, key string, ...) (string, bool, error)
- func ConsumeIfExists(ctx context.Context, client goredis.UniversalClient, key string) (bool, error)
- func DeleteByPattern(ctx context.Context, client goredis.UniversalClient, pattern string, ...) (int, error)
- func JitterTTL(ttl time.Duration, ratio float64) time.Duration
- func NormalizeNamespace(ns string) string
- func ReleaseLease(ctx context.Context, client goredis.UniversalClient, key, token string) error
- func ScanKeys(ctx context.Context, client goredis.UniversalClient, pattern string, ...) ([]string, error)
- type DeleteByPatternOptions
- type Keyspace
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 ¶
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 NormalizeNamespace ¶
NormalizeNamespace trims trailing/leading separators from a Redis namespace.
func ReleaseLease ¶
ReleaseLease releases a lock only when the lease token matches.
Types ¶
type DeleteByPatternOptions ¶
DeleteByPatternOptions controls batched key deletion.
func DefaultDeleteByPatternOptions ¶
func DefaultDeleteByPatternOptions() DeleteByPatternOptions
DefaultDeleteByPatternOptions returns the canonical pattern-deletion defaults.