Skip to content

Commit 4691a9c

Browse files
committed
Add test for single connection
1 parent 0d60ff4 commit 4691a9c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/test_cache.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ def r(request):
1717
cache = request.param.get("cache")
1818
kwargs = request.param.get("kwargs", {})
1919
protocol = request.param.get("protocol", 3)
20+
single_connection_client = request.param.get("single_connection_client", False)
2021
with _get_client(
21-
redis.Redis, request, protocol=protocol, client_cache=cache, **kwargs
22+
redis.Redis,
23+
request,
24+
single_connection_client=single_connection_client,
25+
protocol=protocol,
26+
client_cache=cache,
27+
**kwargs,
2228
) as client:
2329
yield client, cache
2430
# client.flushdb()
@@ -368,6 +374,28 @@ def test_execute_command_keys_not_provided(self, r):
368374
assert r.execute_command("GET", "b") == "2" # keys not provided, not cached
369375
assert cache.get(("GET", "b")) is None
370376

377+
@pytest.mark.parametrize(
378+
"r",
379+
[{"cache": _LocalCache(), "single_connection_client": True}],
380+
indirect=True,
381+
)
382+
def test_single_connection(self, r):
383+
r, cache = r
384+
# add key to redis
385+
r.set("foo", "bar")
386+
# get key from redis and save in local cache
387+
assert r.get("foo") == b"bar"
388+
# get key from local cache
389+
assert cache.get(("GET", "foo")) == b"bar"
390+
# change key in redis (cause invalidation)
391+
r.set("foo", "barbar")
392+
# send any command to redis (process invalidation in background)
393+
r.ping()
394+
# the command is not in the local cache anymore
395+
assert cache.get(("GET", "foo")) is None
396+
# get key from redis
397+
assert r.get("foo") == b"barbar"
398+
371399

372400
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
373401
@pytest.mark.onlycluster

0 commit comments

Comments
 (0)