sessionlock

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

sessionlock package provides support for application level distributed locks via advisory locks in PostgreSQL.

- https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS - https://samu.space/distributed-locking-with-postgres-advisory-locks/

Index

Constants

View Source
const IDPrefix string = "sessionlock-"

IDPrefix is prepended to any given lock name when computing the integer lock ID, to help prevent collisions with other clients that may be acquiring their own locks.

View Source
const SpinWait time.Duration = 100 * time.Millisecond

SpinWait is the amount of time that sessionlock will sleep between attempts to acquire an in-use session lock with `pg_try_advisory_lock`.

Variables

This section is empty.

Functions

func ID

func ID(name string) uint32

ID consistently hashes a string to unique integer that can be used with pg_advisory_lock() and pg_advisory_unlock().

func With

func With(ctx context.Context, db *sql.DB, lockName string, cb func(*sql.Conn) error) (final error)

With will open a connection to the `db`, acquire an advisory lock, use that connection to acquire an advisory lock, then call your `cb`, then release the advisory lock.

With will spin indefinitely using `pg_try_advisory_lock` to acquire the lock, giving up only if the lock is acquired or if the provided `ctx` expires.

Types

This section is empty.

Jump to

Keyboard shortcuts

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