{"id":25268241,"url":"https://github.com/arfnds/postgres-lock","last_synced_at":"2025-04-06T04:19:14.649Z","repository":{"id":275787610,"uuid":"927189308","full_name":"ArFnds/postgres-lock","owner":"ArFnds","description":"Distributed synchronization lock based on PostgreSQL advisory locks.","archived":false,"fork":false,"pushed_at":"2025-02-04T15:04:01.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-12T10:25:00.367Z","etag":null,"topics":["distributed","golang","lock","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArFnds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T14:55:18.000Z","updated_at":"2025-02-04T15:08:13.000Z","dependencies_parsed_at":"2025-02-04T16:31:45.808Z","dependency_job_id":null,"html_url":"https://github.com/ArFnds/postgres-lock","commit_stats":null,"previous_names":["arfnds/postgres-lock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArFnds%2Fpostgres-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArFnds%2Fpostgres-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArFnds%2Fpostgres-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArFnds%2Fpostgres-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArFnds","download_url":"https://codeload.github.com/ArFnds/postgres-lock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247431235,"owners_count":20937916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed","golang","lock","postgresql"],"created_at":"2025-02-12T10:24:24.280Z","updated_at":"2025-04-06T04:19:14.303Z","avatar_url":"https://github.com/ArFnds.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postgres Distributed Lock\n\nThe postgres-lock package offers distributed synchronization lock based on [PostgreSQL advisory locks](https://www.postgresql.org/docs/9.4/explicit-locking.html#ADVISORY-LOCKS). For example:\n\n```go\nctx := context.Background()\nconn, err := pgx.Connect(ctx, \"postgres://postgres:postgres@localhost:5432/postgres\")\nif err != nil {\n    t.Fatalf(\"Failed to connect %v\", err)\n}\ndefer conn.Close(ctx)\n\nlock := postgreslock.NewPostgresDistributedLock(\"test\", conn)\n\nfmt.Println(\"waiting for lock\")\nerr = lock.Acquire(ctx)\nif err != nil {\n    t.Fatalf(\"failed to acquire lock: %v\", err)\n}\ndefer func() {\n    lock.Release(ctx)\n    fmt.Println(\"lock released\")\n}()\n\nfmt.Println(\"lock acquired\")\n\ntime.Sleep(2 * time.Second)\n```\n\n## Implementation notes\n\nUnder the hood, [Postgres advisory locks can be based on either one 64-bit integer value or a pair of 32-bit integer values](https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS). Because of this, the lock take a name that will be hashed in a 64-bit int using FNV-1.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farfnds%2Fpostgres-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farfnds%2Fpostgres-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farfnds%2Fpostgres-lock/lists"}