Metadata-Version: 2.4
Name: rdlock_py
Version: 0.0.1
Summary: A simple distributed lock based on redis.
Author-email: Kevin Chen <1354016594@qq.com>
License-Expression: MIT
Project-URL: Home-page, https://github.com/czf0613/rdlock_py
Keywords: redis,distributed lock,lock
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: redis>=7.1.0
Requires-Dist: setuptools>=80.9.0
Dynamic: license-file

# Redis based distributed lock

This is a simple distributed lock based on redis. It needs asyncio, otherwise it will not work!

You can install it simply with `pip install rdlock_py`

## Usage

1, setup a redis client factory.

2, get a mutex and manage it with the context manager.

``` python
from rdlock import RDLockFactory, MutexOccupiedError

factory = RDLockFactory("redis://:13717421@localhost:30000/0")

while True:
    try:
        async with factory.get_mutex("test_mutex"):
            # do your work here
            break
    except MutexOccupiedError:
        # spin yourself
        await asyncio.sleep(0.01)
```

## Test

Use the `uv run pytest` will automatically test all cases.
