A distributed lock implementation based on SQLAlchemy
Project description
SQLAlchemy-DLock
Distributed lock based on Database and SQLAlchemy.
It currently supports locks of:
MySQL: https://dev.mysql.com/doc/refman/8.0/en/locking-functions.htmlPostgreSQL: https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS
It's not stable and DO NOT use it in production.
Usages
Basic usage:
# ...
from sqlalchemy import create_engine
from sqlalchemy_dlock import sadlock
# ...
lock_key = 'user/001'
# ...
engine = create_engine('postgresql://scott:tiger@localhost/')
# ...
with engine.connect() as conn:
with sadlock(conn, lock_key):
pass
# locked here!
# ...
pass
# unlocked here!
# ...
# ...
Work with SQLAlchemy's Session:
# ...
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_dlock import sadlock
# ...
lock_key = 'user/001'
# ...
engine = create_engine('postgresql://scott:tiger@localhost/')
Session = sessionmaker(bind=engine)
# ...
session = Session()
# ...
with session.bind.connect() as conn:
with sadlock(conn, lock_key):
# locked here!
# ...
user = session.query('User').filter(id='001').one()
user.password = 'new password'
session.commit()
# ...
pass
# unlocked here!
# ...
# ...
CHANGELOG
v0.2a1
Date: 2021-03-08
-
New:
-
Asynchronous IO Support by:
-
aiomysql for MySQL
Connection URL is like:
"mysql+aiomysql://user:password@host:3306/schema?charset=utf8mb4" -
asyncpg for PostgreSQL
Connection URL is like:
"postgresql+asyncpg://user:password@host:5432/db"
Read https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html for details
-
-
v0.1.2
Date: 2021-01-26
Still an early version, not for production.
- Changes:
- Arguments and it's default value of
acquirenow similar to stdlib'smultiprossing.Lock, instead ofThreading.Lock - MySQL lock now accepts float-point value as
timeout
- Arguments and it's default value of
- Adds
- Several new test cases
- Other
- Many other small adjustment
v0.1.1
- A very early version, maybe not stable enough.
- Replace black2b with crc64-iso in PostgreSQL key convert function
- Only named arguments as extra parameters allowed in Lock's implementation class
AUTHORS
-
Liu Xue Yan (liu_xue_yan@foxmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file SQLAlchemy-DLock-0.2a1.tar.gz.
File metadata
- Download URL: SQLAlchemy-DLock-0.2a1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b466b6484dc39b26a16251a7c70efe4197d20710680a046d6e7b3af4041afe5
|
|
| MD5 |
e8a117e2d308fc1b7575bfec99bd94c3
|
|
| BLAKE2b-256 |
41bb52bb58125229783e152c7ab45c35b118cdb9dd2bb91dfb2b950fd855b1bb
|
File details
Details for the file SQLAlchemy_DLock-0.2a1-py3-none-any.whl.
File metadata
- Download URL: SQLAlchemy_DLock-0.2a1-py3-none-any.whl
- Upload date:
- Size: 20.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
199f029bae25c0a9a0d995d71d1463d9257cbc5927218304bcbed704cf25efa7
|
|
| MD5 |
4624f758472a384eb10a8a314bac7f25
|
|
| BLAKE2b-256 |
4ed21a8c6003392b860422378582f7efef03f8c68010b332de31c7480e891e5a
|