sessionlock

package
v0.0.0-...-1c0f521 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 5 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.

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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