redislock

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package redislock is a Redis-backed distributed lock that satisfies lock.Provider. Opt-in: importing this package pulls in github.com/redis/go-redis/v9; the root lock package has no driver dependency.

SET NX PX <ttl_ms> for Acquire (atomic with TTL), Lua check-and-delete for Release so we only delete locks whose token we still own. This protects against a stale releaser stomping a lock that's already been reclaimed after a TTL expiry.

Index

Constants

View Source
const DefaultPrefix = "fc:lock"

DefaultPrefix prepended to every lock key when New is used.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is a Redis-backed implementation of lock.Provider. Pass any redis.UniversalClient — standalone, sentinel, or cluster — so consumers control connection / reconnect handling.

func New

func New(client redis.UniversalClient) *Provider

New builds a provider with DefaultPrefix.

func WithPrefix

func WithPrefix(client redis.UniversalClient, prefix string) *Provider

WithPrefix builds a provider that prepends prefix + ":" to every key.

func (*Provider) Acquire

func (p *Provider) Acquire(ctx context.Context, key string, ttl time.Duration) (lock.Handle, error)

Acquire — see lock.Provider.Acquire.

Jump to

Keyboard shortcuts

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