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 ¶
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.
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 ¶
ID consistently hashes a string to unique integer that can be used with pg_advisory_lock() and pg_advisory_unlock().
func With ¶
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.