Skip to content

Commit f23b06d

Browse files
committed
Fixed merge conflicts
2 parents df4fd4d + 196544b commit f23b06d

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
django-version:
2121
- '4.2'
2222
- '5.0'
23+
- '5.1'
2324
redis-version:
2425
- 'latest'
2526

@@ -36,7 +37,7 @@ jobs:
3637
python-version: '3.9'
3738

3839
# latest Django with pre-release redis
39-
- django-version: '5.0'
40+
- django-version: '5.1'
4041
redis-version: 'master'
4142
python-version: '3.11'
4243

changelog.d/752.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added blocking parameter for `cache.lock`

changelog.d/754.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for django 5.1

django_redis/client/default.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ def expire(
326326

327327
key = self.make_key(key, version=version)
328328

329-
# for some strange reason mypy complains,
330-
# saying that timeout type is float | timedelta
331329
return client.expire(key, timeout)
332330

333331
def pexpire(
@@ -345,10 +343,6 @@ def pexpire(
345343

346344
key = self.make_key(key, version=version)
347345

348-
# Temporary casting until https://github.com/redis/redis-py/issues/1664
349-
# is fixed.
350-
# for some strange reason mypy complains,
351-
# saying that timeout type is float | timedelta
352346
return bool(client.pexpire(key, timeout))
353347

354348
def pexpire_at(
@@ -393,6 +387,7 @@ def lock(
393387
version: Optional[int] = None,
394388
timeout: Optional[float] = None,
395389
sleep: float = 0.1,
390+
blocking: bool = True,
396391
blocking_timeout: Optional[float] = None,
397392
client: Optional[Redis] = None,
398393
thread_local: bool = True,
@@ -405,6 +400,7 @@ def lock(
405400
key,
406401
timeout=timeout,
407402
sleep=sleep,
403+
blocking=blocking,
408404
blocking_timeout=blocking_timeout,
409405
thread_local=thread_local,
410406
)

setup.cfg

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ classifiers =
1414
Framework :: Django
1515
Framework :: Django :: 4.2
1616
Framework :: Django :: 5.0
17+
Framework :: Django :: 5.1
1718
Intended Audience :: Developers
1819
License :: OSI Approved :: BSD License
1920
Operating System :: OS Independent
@@ -56,9 +57,9 @@ envlist =
5657
ruff
5758
mypy
5859
# tests against released versions
59-
py{38,39,310,311}-dj{42,50}-redislatest
60+
py{38,39,310,311}-dj{42,50,51}-redislatest
6061
# tests against unreleased versions
61-
py311-dj50-redismaster
62+
py311-dj51-redismaster
6263
py311-djmain-redis{latest,master}
6364

6465
[gh-actions]
@@ -72,6 +73,7 @@ python =
7273
DJANGO =
7374
4.2: dj42
7475
5.0: dj50
76+
5.1: dj51
7577
main: djmain
7678
REDIS =
7779
latest: redislatest
@@ -98,6 +100,7 @@ commands =
98100
deps =
99101
dj42: Django>=4.2,<5.0
100102
dj50: Django>=5.0,<5.1
103+
dj51: Django>=5.1,<5.2
101104
djmain: https://github.com/django/django/archive/main.tar.gz
102105
msgpack>=0.6.0
103106
pytest

tests/test_backend.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,15 +677,27 @@ def test_expire_at(self, cache: RedisCache):
677677

678678
def test_lock(self, cache: RedisCache):
679679
lock = cache.lock("foobar")
680-
lock.acquire(blocking=True)
680+
assert lock.acquire(blocking=True)
681+
682+
assert cache.has_key("foobar")
683+
lock.release()
684+
assert not cache.has_key("foobar")
685+
686+
def test_lock_not_blocking(self, cache: RedisCache):
687+
lock = cache.lock("foobar")
688+
assert lock.acquire(blocking=False)
689+
690+
lock2 = cache.lock("foobar")
691+
692+
assert not lock2.acquire(blocking=False)
681693

682694
assert cache.has_key("foobar")
683695
lock.release()
684696
assert not cache.has_key("foobar")
685697

686698
def test_lock_released_by_thread(self, cache: RedisCache):
687699
lock = cache.lock("foobar", thread_local=False)
688-
lock.acquire(blocking=True)
700+
assert lock.acquire(blocking=True)
689701

690702
def release_lock(lock_):
691703
lock_.release()

0 commit comments

Comments
 (0)