postgres

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLock

func NewLock(db *sqlx.DB, retry time.Duration) *lock

Types

type Pool added in v0.1.0

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

Pool implements a distlock.Locker backed by a pgxpool.Pool.

func NewPool added in v0.1.0

func NewPool(pool *pgxpool.Pool, retry time.Duration) *Pool

NewPool returns a lock struct backed by the provided connection pool.

The returned lock can be reused

func (*Pool) Lock added in v0.1.0

func (p *Pool) Lock(ctx context.Context, key string) error

Lock attempts to take the lock identified by 'key', blocking and retrying on the period specified at creation until successful or the provided context is cancelled.

func (*Pool) TryLock added in v0.1.0

func (p *Pool) TryLock(ctx context.Context, key string) (bool, error)

TryLock is a nonblocking attempt at taking the lock identified by 'key'.

If successful, the duration of the lock is tied to the provided context; that is, if the context is canceled the lock will automatically be released.

func (*Pool) Unlock added in v0.1.0

func (p *Pool) Unlock() error

Unlock releases a held lock and resets the lock for future use.

Jump to

Keyboard shortcuts

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