@@ -17,8 +17,14 @@ def r(request):
17
17
cache = request .param .get ("cache" )
18
18
kwargs = request .param .get ("kwargs" , {})
19
19
protocol = request .param .get ("protocol" , 3 )
20
+ single_connection_client = request .param .get ("single_connection_client" , False )
20
21
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 ,
22
28
) as client :
23
29
yield client , cache
24
30
# client.flushdb()
@@ -368,6 +374,28 @@ def test_execute_command_keys_not_provided(self, r):
368
374
assert r .execute_command ("GET" , "b" ) == "2" # keys not provided, not cached
369
375
assert cache .get (("GET" , "b" )) is None
370
376
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
+
371
399
372
400
@pytest .mark .skipif (HIREDIS_AVAILABLE , reason = "PythonParser only" )
373
401
@pytest .mark .onlycluster
0 commit comments