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.html
- PostgreSQL: https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS
It's not stable and DO NOT use it in production.
Usages
Basic:
from sqlalchemy import create_engine
from sqlalchemy_dlock import make_session_level_lock as sd_lock
# ...
lock_key = 'user/001'
# ...
engine = create_engine()
# ...
with engine.connect() as conn:
with sd_lock(conn, lock_key):
# do sth...
pass
# ...
Made from SQLAlchemy's Session:
# ...
lock_key = 'user/001'
# ...
with Session.bind.connect() as conn:
with sd_lock(conn, lock_key):
# ...
user = Session.query(User).filter(id='001').one()
user.password = new_pass
Session.commit()
# ...
# ...
Or, if the session
has no commit
, rollback
, close
:
# ...
lock_key = 'user/001'
# ...
with sd_lock(Session.connection(), lock_key):
# ...
user = Session.query(User).filter(id='001').one()
password = user.password
# ...
# ...
CHANGELOG
v0.1.1
- An 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
Close
Hashes for SQLAlchemy-DLock-0.1.1.post1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca2ca80c77bee6ce7cdc86bba554ca674c2a5247ce7121527f63f4ceb344f2b |
|
MD5 | fccf48d25f0791a69bfb57b5e1910c1c |
|
BLAKE2b-256 | ceb7998cba426f5fbe898e800f00d4a665c254f2f0af5eac6e808010288afdff |
Close
Hashes for SQLAlchemy_DLock-0.1.1.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6310e81a22c09d260aa31f1747a2f22fcd53b6cd2ffd6a34bc7a85026995b2dd |
|
MD5 | ebf834c0f081cd7974a12ff0cd64bf22 |
|
BLAKE2b-256 | bf7c3e31ac73d68ef946d7f5bebe4e6a52316e4aa4bb0100e076d958fe77d751 |