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 usage:
# ...
from sqlalchemy import create_engine
from sqlalchemy_dlock import make_sa_dlock
# ...
lock_key = 'user/001'
# ...
engine = create_engine('postgresql://scott:tiger@localhost/')
# ...
with engine.connect() as conn:
with make_sa_dlock(conn, lock_key):
# do sth...
pass
# ...
Work with SQLAlchemy's Session:
# ...
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_dlock import make_sa_dlock
# ...
lock_key = 'user/001'
# ...
engine = create_engine('postgresql://scott:tiger@localhost/')
Session = sessionmaker(bind=engine)
# ...
session = Session()
# ...
with session.bind.connect() as conn:
with make_sa_dlock(conn, lock_key):
# ...
user = session.query('User').filter(id='001').one()
user.password = 'new password'
session.commit()
# ...
# ...
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.post2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac59fb55bb2983f47db297b598491ee092dd2cdc840fdb828a561039a757eb2e |
|
MD5 | d2adc62f663308d3872f222afe83d5c3 |
|
BLAKE2b-256 | 6e70f0ce6ad341c82a8470453482fb671265c7e1e812915056904109a6bc811d |
Close
Hashes for SQLAlchemy_DLock-0.1.1.post2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096bb4dd4a77793359a883e2d3fcac1f3ffe82274ac590eb5988ebc39f9f3828 |
|
MD5 | f54190b1bd84a1fc55d5669bd62515ef |
|
BLAKE2b-256 | 8cbf49413e1a44c5cd9ecf84a6a0ff4fc93f147ca8712b5c4e3c1f1a690852bc |