File tree 3 files changed +15
-4
lines changed 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -864,6 +864,10 @@ def test_object(self, r):
864
864
865
865
def test_ping (self , r ):
866
866
assert r .ping ()
867
+ assert r .ping (0 )
868
+ assert r .ping ("Valkey" )
869
+ assert r .ping (" Valkey " )
870
+ assert r .ping ("Valkey" , test = "a" )
867
871
868
872
@pytest .mark .onlynoncluster
869
873
def test_quit (self , r ):
Original file line number Diff line number Diff line change 1
1
import datetime
2
2
3
- from valkey .utils import str_if_bytes
3
+ from valkey .utils import str_if_bytes , safe_str
4
4
5
5
6
6
def timestamp_to_datetime (response ):
@@ -684,6 +684,12 @@ def parse_set_result(response, **options):
684
684
return response and str_if_bytes (response ) == "OK"
685
685
686
686
687
+ def parse_ping (response , ** options ):
688
+ response = str_if_bytes (response )
689
+ message = "PONG" if options .get ("message" ) is None else options .get ("message" )
690
+ return response == safe_str (message )
691
+
692
+
687
693
def string_keys_to_dict (key_string , callback ):
688
694
return dict .fromkeys (key_string .split (), callback )
689
695
@@ -747,7 +753,7 @@ def string_keys_to_dict(key_string, callback):
747
753
"MEMORY PURGE" : bool_ok ,
748
754
"MODULE LOAD" : bool ,
749
755
"MODULE UNLOAD" : bool ,
750
- "PING" : lambda r : str_if_bytes ( r ) == "PONG" ,
756
+ "PING" : parse_ping ,
751
757
"PUBSUB NUMSUB" : parse_pubsub_numsub ,
752
758
"PUBSUB SHARDNUMSUB" : parse_pubsub_numsub ,
753
759
"QUIT" : bool_ok ,
Original file line number Diff line number Diff line change @@ -1203,13 +1203,14 @@ def latency_reset(self, *events: str) -> ResponseT:
1203
1203
"""
1204
1204
return self .execute_command ("LATENCY RESET" , * events )
1205
1205
1206
- def ping (self , ** kwargs ) -> ResponseT :
1206
+ def ping (self , message = None , ** kwargs ) -> ResponseT :
1207
1207
"""
1208
1208
Ping the Valkey server
1209
1209
1210
1210
For more information see https://valkey.io/commands/ping
1211
1211
"""
1212
- return self .execute_command ("PING" , ** kwargs )
1212
+ args = ["PING" , message ] if message is not None else ["PING" ]
1213
+ return self .execute_command (* args , message = message , ** kwargs )
1213
1214
1214
1215
def quit (self , ** kwargs ) -> ResponseT :
1215
1216
"""
You can’t perform that action at this time.
0 commit comments