Skip to content

Commit 2c50adc

Browse files
committed
Initial take on Sentinel support
1 parent eb95bd3 commit 2c50adc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def sslclient(request):
410410

411411

412412
@pytest.fixture()
413-
def sentinel_setup(local_cache, request):
413+
def sentinel_setup(cache, request):
414414
sentinel_ips = request.config.getoption("--sentinels")
415415
sentinel_endpoints = [
416416
(ip.strip(), int(port.strip()))
@@ -420,7 +420,8 @@ def sentinel_setup(local_cache, request):
420420
sentinel = Sentinel(
421421
sentinel_endpoints,
422422
socket_timeout=0.1,
423-
client_cache=local_cache,
423+
use_cache=cache,
424+
cache=cache,
424425
protocol=3,
425426
**kwargs,
426427
)

tests/test_cache.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,21 @@ def test_cache_flushed_on_server_flush(self, r, cache):
488488
assert r.flushall()
489489
assert r.get("foo") is None
490490
assert cache.currsize == 0
491+
492+
@pytest.mark.skipif(HIREDIS_AVAILABLE, reason="PythonParser only")
493+
@pytest.mark.onlynoncluster
494+
class TestSentinelCache:
495+
def test_get_from_cache(self, cache, master):
496+
master.set("foo", "bar")
497+
# get key from redis and save in local cache
498+
assert master.get("foo") == b"bar"
499+
# get key from local cache
500+
assert cache.get(("GET", "foo")) == b"bar"
501+
# change key in redis (cause invalidation)
502+
master.set("foo", "barbar")
503+
# send any command to redis (process invalidation in background)
504+
master.ping()
505+
# the command is not in the local cache anymore
506+
assert cache.get(("GET", "foo")) is None
507+
# get key from redis
508+
assert master.get("foo") == b"barbar"

0 commit comments

Comments
 (0)