sqlalchemy_dlock.lock.mysql module¶
- class sqlalchemy_dlock.lock.mysql.MysqlAsyncSadLock(connection_or_session, key, **kwargs)[source]¶
Bases:
MysqlSadLockMixin,BaseAsyncSadLock[str,AsyncConnection|AsyncSession|async_scoped_session]Async IO version of
MysqlSadLock- Parameters:
key (
Any) –MySQL named lock requires the key given by string.
If
keyis not astr:convert –
Custom function to covert
keyto required data type.Example
def convert(value) -> str: # get a string key by `value` return the_string_covert_from_value
connection_or_session (AsyncConnection | AsyncSession | async_scoped_session)
- class sqlalchemy_dlock.lock.mysql.MysqlSadLock(connection_or_session, key, **kwargs)[source]¶
Bases:
MysqlSadLockMixin,BaseSadLock[str,Connection|Session|scoped_session]A distributed lock implemented by MySQL named-lock
Caution
To MySQL locking function, it is even possible for a given session to acquire multiple locks for the same name. Other sessions cannot acquire a lock with that name until the acquiring session releases all its locks for the name. When perform multiple
acquire()for a key on the same SQLAlchemy connection, latteracquire()will success immediately no wait and never block, it causes cascade lock instead!- Parameters:
connection_or_session (
Connection|Session|scoped_session) –BaseSadLock.connection_or_sessionkey (
Any) –BaseSadLock.key**kwargs – other named parameters pass to
BaseSadLockandMysqlSadLockMixin
- class sqlalchemy_dlock.lock.mysql.MysqlSadLockMixin(*, key, convert=None, **kwargs)[source]¶
Bases:
AbstractLockMixin[KTV,str]A Mix-in class for MySQL named lock
- Parameters:
key (
TypeVar(KTV, bound=Any)) –MySQL named lock requires the key given by string.
If
keyis not astr:convert (
Callable[[TypeVar(KTV, bound=Any)],str] |None) –Custom function to covert
keyto required data type.Example
def convert(value) -> str: # get a string key by `value` return the_string_covert_from_value