mirror of
https://github.com/django/django.git
synced 2025-03-12 02:12:38 +00:00
Fixed #34212 -- Made RedisCacheClient.incr() use write connection.
Co-authored-by: Sin-Woo Bang <sinwoobang@gmail.com>
This commit is contained in:
parent
1e4da43955
commit
a1bcdc94da
2
django/core/cache/backends/redis.py
vendored
2
django/core/cache/backends/redis.py
vendored
@ -130,7 +130,7 @@ class RedisCacheClient:
|
|||||||
return bool(client.exists(key))
|
return bool(client.exists(key))
|
||||||
|
|
||||||
def incr(self, key, delta):
|
def incr(self, key, delta):
|
||||||
client = self.get_client(key)
|
client = self.get_client(key, write=True)
|
||||||
if not client.exists(key):
|
if not client.exists(key):
|
||||||
raise ValueError("Key '%s' not found." % key)
|
raise ValueError("Key '%s' not found." % key)
|
||||||
return client.incr(key, delta)
|
return client.incr(key, delta)
|
||||||
|
8
tests/cache/tests.py
vendored
8
tests/cache/tests.py
vendored
@ -1787,6 +1787,14 @@ class RedisCacheTests(BaseCacheTests, TestCase):
|
|||||||
def incr_decr_type_error(self):
|
def incr_decr_type_error(self):
|
||||||
return self.lib.ResponseError
|
return self.lib.ResponseError
|
||||||
|
|
||||||
|
def test_incr_write_connection(self):
|
||||||
|
cache.set("number", 42)
|
||||||
|
with mock.patch(
|
||||||
|
"django.core.cache.backends.redis.RedisCacheClient.get_client"
|
||||||
|
) as mocked_get_client:
|
||||||
|
cache.incr("number")
|
||||||
|
self.assertEqual(mocked_get_client.call_args.kwargs, {"write": True})
|
||||||
|
|
||||||
def test_cache_client_class(self):
|
def test_cache_client_class(self):
|
||||||
self.assertIs(cache._class, RedisCacheClient)
|
self.assertIs(cache._class, RedisCacheClient)
|
||||||
self.assertIsInstance(cache._cache, RedisCacheClient)
|
self.assertIsInstance(cache._cache, RedisCacheClient)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user