Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to django 5.1 #754

Merged
merged 17 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
django-version:
- '4.2'
- '5.0'
- '5.1'
redis-version:
- 'latest'

Expand All @@ -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'

Expand Down
1 change: 1 addition & 0 deletions changelog.d/752.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added blocking parameter for `cache.lock`
1 change: 1 addition & 0 deletions changelog.d/754.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for django 5.1
12 changes: 4 additions & 8 deletions django_redis/client/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ 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) # type: ignore
return client.expire(key, timeout)

def pexpire(
self,
Expand All @@ -345,11 +343,7 @@ 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)) # type: ignore
return bool(client.pexpire(key, timeout))

def pexpire_at(
self,
Expand Down Expand Up @@ -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,
Expand All @@ -405,6 +400,7 @@ def lock(
key,
timeout=timeout,
sleep=sleep,
blocking=blocking,
blocking_timeout=blocking_timeout,
thread_local=thread_local,
)
Expand Down
4 changes: 1 addition & 3 deletions django_redis/client/herd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ def _is_expired(x, herd_timeout: int) -> bool:
return True
val = x + random.randint(1, herd_timeout)

if val >= herd_timeout:
return True
return False
return val >= herd_timeout


class HerdClient(DefaultClient):
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -72,6 +73,7 @@ python =
DJANGO =
4.2: dj42
5.0: dj50
5.1: dj51
main: djmain
REDIS =
latest: redislatest
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,27 @@

def test_lock(self, cache: RedisCache):
lock = cache.lock("foobar")
lock.acquire(blocking=True)
assert lock.acquire(blocking=True)

Check warning on line 680 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L680

Added line #L680 was not covered by tests

assert cache.has_key("foobar")
lock.release()
assert not cache.has_key("foobar")

Check warning on line 684 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L682-L684

Added lines #L682 - L684 were not covered by tests

def test_lock_not_blocking(self, cache: RedisCache):
lock = cache.lock("foobar")
assert lock.acquire(blocking=False)

Check warning on line 688 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L686-L688

Added lines #L686 - L688 were not covered by tests

lock2 = cache.lock("foobar")

Check warning on line 690 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L690

Added line #L690 was not covered by tests

assert not lock2.acquire(blocking=False)

Check warning on line 692 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L692

Added line #L692 was not covered by tests

assert cache.has_key("foobar")
lock.release()
assert not cache.has_key("foobar")

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)

Check warning on line 700 in tests/test_backend.py

View check run for this annotation

Codecov / codecov/patch

tests/test_backend.py#L700

Added line #L700 was not covered by tests

def release_lock(lock_):
lock_.release()
Expand Down
Loading