postgres

package
v0.0.0-...-fc7c8a0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

type Locker struct {
	Logger locker.Logger

	Hash32A func() hash.Hash32
	Hash32B func() hash.Hash32
	// contains filtered or unexported fields
}

Locker is an implementation of the locker.Locker using PostgreSQL pg_advisory_lock

func NewLocker

func NewLocker(db *sql.DB) *Locker

NewLocker creates a new Locker

func (*Locker) Get

func (r *Locker) Get(ctx context.Context, key string) (locker.Lock, error)

Get calls PostgreSQL pg_advisory_lock(keyA int, keyB int) to acquire the lock. Since these pg_advisory_lock keys are 32-bit integers, this method uses two different hash functions to convert the argument string keys to integers and uses them as the keys for pg_advisory_lock. Default hash functions are FNV-1a hash and Murmur hash.

func (*Locker) GetByRawKey

func (r *Locker) GetByRawKey(ctx context.Context, keyA, keyB int32) (locker.Lock, error)

GetByRawKey calls PostgreSQL pg_advisory_lock(keyA int, keyB int) to acquire the lock.

Jump to

Keyboard shortcuts

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