Metadata-Version: 2.4
Name: rdlock_py
Version: 0.1.0
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, LockError, LockTimeout

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

try:
    async with factory.get_mutex("test_mutex", "my_owner", 1.0):
        # do your work here
        pass
except LockTimeout:
    print("failed to get lock in several seconds...")
except LockError:
    print("Something wrong when communicating with redis")
```

## Test

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