diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30b52ba9..f42b4ef9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: django-version: - '4.2' - '5.0' + - '5.1' redis-version: - 'latest' @@ -36,7 +37,7 @@ jobs: python-version: '3.9' # latest Django with pre-release redis - - django-version: '5.0' + - django-version: '5.1' redis-version: 'master' python-version: '3.11' diff --git a/changelog.d/752.bugfix b/changelog.d/752.bugfix new file mode 100644 index 00000000..68c94278 --- /dev/null +++ b/changelog.d/752.bugfix @@ -0,0 +1 @@ +Added blocking parameter for `cache.lock` \ No newline at end of file diff --git a/changelog.d/754.misc b/changelog.d/754.misc new file mode 100644 index 00000000..4945394e --- /dev/null +++ b/changelog.d/754.misc @@ -0,0 +1 @@ +Added support for django 5.1 \ No newline at end of file diff --git a/django_redis/client/default.py b/django_redis/client/default.py index b0827f72..940e1a0e 100644 --- a/django_redis/client/default.py +++ b/django_redis/client/default.py @@ -326,8 +326,6 @@ def expire( key = self.make_key(key, version=version) - # for some strange reason mypy complains, - # saying that timeout type is float | timedelta return client.expire(key, timeout) def pexpire( @@ -345,10 +343,6 @@ def pexpire( key = self.make_key(key, version=version) - # Temporary casting until https://github.com/redis/redis-py/issues/1664 - # is fixed. - # for some strange reason mypy complains, - # saying that timeout type is float | timedelta return bool(client.pexpire(key, timeout)) def pexpire_at( @@ -393,6 +387,7 @@ def lock( version: Optional[int] = None, timeout: Optional[float] = None, sleep: float = 0.1, + blocking: bool = True, blocking_timeout: Optional[float] = None, client: Optional[Redis] = None, thread_local: bool = True, @@ -405,6 +400,7 @@ def lock( key, timeout=timeout, sleep=sleep, + blocking=blocking, blocking_timeout=blocking_timeout, thread_local=thread_local, ) diff --git a/setup.cfg b/setup.cfg index fbbc9113..08781667 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,6 +14,7 @@ classifiers = Framework :: Django Framework :: Django :: 4.2 Framework :: Django :: 5.0 + Framework :: Django :: 5.1 Intended Audience :: Developers License :: OSI Approved :: BSD License Operating System :: OS Independent @@ -56,9 +57,9 @@ envlist = ruff mypy # tests against released versions - py{38,39,310,311}-dj{42,50}-redislatest + py{38,39,310,311}-dj{42,50,51}-redislatest # tests against unreleased versions - py311-dj50-redismaster + py311-dj51-redismaster py311-djmain-redis{latest,master} [gh-actions] @@ -72,6 +73,7 @@ python = DJANGO = 4.2: dj42 5.0: dj50 + 5.1: dj51 main: djmain REDIS = latest: redislatest @@ -98,6 +100,7 @@ commands = deps = dj42: Django>=4.2,<5.0 dj50: Django>=5.0,<5.1 + dj51: Django>=5.1,<5.2 djmain: https://github.com/django/django/archive/main.tar.gz msgpack>=0.6.0 pytest diff --git a/tests/test_backend.py b/tests/test_backend.py index 8619931e..e5c54e18 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -677,7 +677,19 @@ def test_expire_at(self, cache: RedisCache): def test_lock(self, cache: RedisCache): lock = cache.lock("foobar") - lock.acquire(blocking=True) + assert lock.acquire(blocking=True) + + assert cache.has_key("foobar") + lock.release() + assert not cache.has_key("foobar") + + def test_lock_not_blocking(self, cache: RedisCache): + lock = cache.lock("foobar") + assert lock.acquire(blocking=False) + + lock2 = cache.lock("foobar") + + assert not lock2.acquire(blocking=False) assert cache.has_key("foobar") lock.release() @@ -685,7 +697,7 @@ def test_lock(self, cache: RedisCache): def test_lock_released_by_thread(self, cache: RedisCache): lock = cache.lock("foobar", thread_local=False) - lock.acquire(blocking=True) + assert lock.acquire(blocking=True) def release_lock(lock_): lock_.release()