memolock

package
v0.0.0-...-a7fa76c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosing = errors.New("Operation canceled by Close()")

ErrClosing happens when calling Close(), all pending requests will be failed with this error

View Source
var ErrLockRenew = errors.New("Unable to renew the lock")

ErrLockRenew happens when trying to renew a lock that expired already

View Source
var ErrTimeOut = errors.New("Operation Timed Out")

ErrTimeOut happens when the given timeout expires

Functions

This section is empty.

Types

type ExternalFetchFunc

type ExternalFetchFunc = func() error

ExternalFetchFunc has the same purpose as FetchFunc but works on the assumption that the value will be set in Redis and notificed on Pub/Sub by an external program

type FetchFunc

type FetchFunc = func() (string, time.Duration, error)

FetchFunc is the function that the caller should provide to compute the value if not present in Redis already. time.Duration defines for how long the value should be cached in Redis.

type LockRenewFunc

type LockRenewFunc = func(time.Duration) error

LockRenewFunc is the function that RenewableFetchFunc will get as input and that must be called to extend a locks' life

type RedisMemoLock

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

RedisMemoLock implements the "promise" mechanism

func NewRedisMemoLock

func NewRedisMemoLock(client *redis.Client, resourceTag string, lockTimeout time.Duration) (*RedisMemoLock, error)

NewRedisMemoLock Creates a new RedisMemoLock instance

func (*RedisMemoLock) Close

func (r *RedisMemoLock) Close()

Close stops listening to Pub/Sub and resolves all pending subscriptions with ErrClosing.

func (*RedisMemoLock) GetResource

func (r *RedisMemoLock) GetResource(resID string, timeout time.Duration, generatingFunc FetchFunc) (string, error)

GetResource tries to get a resource from Redis, resorting to call generatingFunc in case of a cache miss

func (*RedisMemoLock) GetResourceExternal

func (r *RedisMemoLock) GetResourceExternal(resID string, timeout time.Duration, generatingFunc ExternalFetchFunc) (string, error)

GetResourceExternal assumes that the value will be set on Redis and notified on Pub/Sub by another program. Useful for when generatingFunc launches an executable instead of doing the work in the current context.

func (*RedisMemoLock) GetResourceRenewable

func (r *RedisMemoLock) GetResourceRenewable(resID string, timeout time.Duration, generatingFunc RenewableFetchFunc) (string, error)

GetResourceRenewable has the same purpose as GetResource but allows the caller to extend the lock lease during the execution of generatingFunc

type RenewableFetchFunc

type RenewableFetchFunc = func(LockRenewFunc) (string, time.Duration, error)

RenewableFetchFunc has the same purpose as FetchFunc but, when called, it is offered a function that allows to extend the lock

Jump to

Keyboard shortcuts

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