redislock

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotObtained is returned when a lock cannot be obtained.
	ErrNotObtained = errors.New("redislock: not obtained")

	// ErrLockNotHeld is returned when trying to release an inactive lock.
	ErrLockNotHeld = errors.New("redislock: lock not held")
)

Functions

This section is empty.

Types

type Client

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

Client wraps a redis client.

func New

func New(client redis.Scripter) *Client

New creates a new Client instance with a custom namespace.

func (*Client) GetData

func (c *Client) GetData(ctx context.Context, key string) (*Data, error)

func (*Client) Obtain

func (c *Client) Obtain(ctx context.Context, key string, ttl time.Duration) (*Lock, error)

Obtain tries to obtain a new lock using a key with the given TTL. May return ErrNotObtained if not successful.

func (*Client) SetData

func (c *Client) SetData(ctx context.Context, key string, data interface{}, err error, ttl time.Duration) error

type Data

type Data struct {
	Err  string
	Data string
}

type Lock

type Lock struct {
	*Client
	// contains filtered or unexported fields
}

Lock represents an obtained, distributed lock.

func Obtain

func Obtain(ctx context.Context, client redis.Scripter, key string, ttl time.Duration) (*Lock, error)

Obtain is a short-cut for New(...).Obtain(...).

func (*Lock) Key

func (l *Lock) Key() string

Key returns the redis key used by the lock.

func (*Lock) Refresh

func (l *Lock) Refresh(ctx context.Context, ttl time.Duration) error

Refresh extends the lock with a new TTL. May return ErrNotObtained if refresh is unsuccessful.

func (*Lock) Release

func (l *Lock) Release(ctx context.Context) error

Release manually releases the lock. May return ErrLockNotHeld.

func (*Lock) TTL

func (l *Lock) TTL(ctx context.Context) (time.Duration, error)

TTL returns the remaining time-to-live. Returns 0 if the lock has expired.

func (*Lock) Token

func (l *Lock) Token() string

Token returns the token value set by the lock.

Jump to

Keyboard shortcuts

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