distsync

package
v0.0.0-...-34c5bf1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalLocksmith

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

LocalLocksmith implements process-scoped locking

func NewLocalLocksmith

func NewLocalLocksmith() *LocalLocksmith

NewLocalLocksmith returns an initialised LocalLocksmith

func (*LocalLocksmith) Forge

func (l *LocalLocksmith) Forge(resource string) (Locker, error)

Forge returns a Locker for the resource

type Locker

type Locker interface {
	Lock(ctx context.Context) error

	// Unlock releases the lock. Implementations of this can fail to unlock for
	// various reasons, so arguably this function should return an error. In
	// practice though, there's nothing useful you can do with the error and
	// the lock will expire at some point anyway.
	Unlock()
}

Locker is a lock on a resource that can be locked and unlocked

func Lock

func Lock(ctx context.Context, resource string, args ...interface{}) (Locker, error)

Lock will forge a lock for the resource and try to acquire the lock

type Locksmith

type Locksmith interface {
	Forge(string) (Locker, error)
}

Locksmith can forge locks

var DefaultLocksmith Locksmith

DefaultLocksmith is a global instance of Locksmith

type RedisLocksmith

type RedisLocksmith struct {
	// ServiceName is used to scope locks to the current service only
	ServiceName string

	// Client is a Redis client
	Client *redis.Client

	// Timeout is the length of time to wait when trying to
	// acquire a lock before giving up and returning an error
	Timeout time.Duration

	// Expiration is the TTL to set on locks
	Expiration time.Duration
}

RedisLocksmith is a Locksmith backed by Redis. It is important that there is only a single Redis node. This algorithm will not work with a Redis cluster.

func (*RedisLocksmith) Forge

func (l *RedisLocksmith) Forge(resource string) (Locker, error)

Forge returns a Locker that can be locked and unlocked

Jump to

Keyboard shortcuts

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