redlock

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// DefaultRetryCount is the max retry times for lock acquire
	DefaultRetryCount = 10

	// DefaultRetryDelay is upper wait time in millisecond for lock acquire retry
	DefaultRetryDelay = 200

	// ClockDriftFactor is clock drift factor, more information refers to doc
	ClockDriftFactor = 0.01

	// UnlockScript is redis lua script to release a lock
	UnlockScript = `` /* 155-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type KVCache added in v1.1.0

type KVCache interface {
	// Set sets the key value with its expiry in milliseconds
	Set(key, val string, expiry int64) *LockElem

	// Get queries LockElem from given key
	Get(key string) *LockElem

	// Delete removes the LockElem with given key from storage
	Delete(key string)

	// Size returns element count in kv storage
	Size() int

	// GC cleans the expired LockElem stored in storage
	GC()
}

KVCache defines interface for redlock key value storage

type LockElem added in v1.1.0

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

LockElem keeps a lock element

type RedClient

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

RedClient holds client to redis

type RedLock

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

RedLock holds the redis lock

func NewRedLock

func NewRedLock(addrs []string) (*RedLock, error)

NewRedLock creates a RedLock

func (*RedLock) Lock

func (r *RedLock) Lock(resource string, ttl int) (int64, error)

Lock acquires a distribute lock

func (*RedLock) SetRetryCount

func (r *RedLock) SetRetryCount(count int)

SetRetryCount sets acquire lock retry count

func (*RedLock) SetRetryDelay

func (r *RedLock) SetRetryDelay(delay int)

SetRetryDelay sets acquire lock retry max internal in millisecond

func (*RedLock) UnLock

func (r *RedLock) UnLock(resource string) error

UnLock releases an acquired lock

type SimpleCache added in v1.1.0

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

SimpleCache is the most negative implementation of KVCache interface

func NewSimpleCache added in v1.1.0

func NewSimpleCache() *SimpleCache

NewSimpleCache creates a new SimpleCache object

func (*SimpleCache) Delete added in v1.1.0

func (sc *SimpleCache) Delete(key string)

Delete implements KVCache.Delete

func (*SimpleCache) GC added in v1.1.0

func (sc *SimpleCache) GC()

GC implements KVCache.GC

func (*SimpleCache) Get added in v1.1.0

func (sc *SimpleCache) Get(key string) *LockElem

Get implements KVCache.Get

func (*SimpleCache) Set added in v1.1.0

func (sc *SimpleCache) Set(key, val string, expiry int64) *LockElem

Set implements KVCache.Set

func (*SimpleCache) Size added in v1.1.1

func (sc *SimpleCache) Size() int

Size implements KVCache.Size

Jump to

Keyboard shortcuts

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