@@ -76,7 +76,7 @@ public function setUp() {
76
76
$ info = $ this ->redis ->info ();
77
77
$ this ->version = (isset ($ info ['redis_version ' ])?$ info ['redis_version ' ]:'0.0.0 ' );
78
78
$ this ->is_keydb = $ this ->detectKeyDB ($ info );
79
- $ this ->is_valkey = $ this ->detectValKey ($ info );
79
+ $ this ->is_valkey = $ this ->detectValKey ($ info );
80
80
}
81
81
82
82
protected function minVersionCheck ($ version ) {
@@ -4958,6 +4958,104 @@ public function testSerializerPHP() {
4958
4958
$ this ->redis ->setOption (Redis::OPT_PREFIX , '' );
4959
4959
}
4960
4960
4961
+ private function cartesianProduct (array $ arrays ) {
4962
+ $ result = [[]];
4963
+
4964
+ foreach ($ arrays as $ array ) {
4965
+ $ append = [];
4966
+ foreach ($ result as $ product ) {
4967
+ foreach ($ array as $ item ) {
4968
+ $ newProduct = $ product ;
4969
+ $ newProduct [] = $ item ;
4970
+ $ append [] = $ newProduct ;
4971
+ }
4972
+ }
4973
+
4974
+ $ result = $ append ;
4975
+ }
4976
+
4977
+ return $ result ;
4978
+ }
4979
+
4980
+ public function testIgnoreNumbers () {
4981
+ $ combinations = $ this ->cartesianProduct ([
4982
+ [false , true , false ],
4983
+ $ this ->getSerializers (),
4984
+ $ this ->getCompressors (),
4985
+ ]);
4986
+
4987
+ foreach ($ combinations as [$ ignore , $ serializer , $ compression ]) {
4988
+ $ this ->redis ->setOption (Redis::OPT_PACK_IGNORE_NUMBERS , $ ignore );
4989
+ $ this ->redis ->setOption (Redis::OPT_SERIALIZER , $ serializer );
4990
+ $ this ->redis ->setOption (Redis::OPT_COMPRESSION , $ compression );
4991
+
4992
+ $ this ->assertIsInt ($ this ->redis ->del ('answer ' ));
4993
+ $ this ->assertIsInt ($ this ->redis ->del ('hash ' ));
4994
+
4995
+ $ transparent = $ compression === Redis::COMPRESSION_NONE &&
4996
+ ($ serializer === Redis::SERIALIZER_NONE ||
4997
+ $ serializer === Redis::SERIALIZER_JSON );
4998
+
4999
+ if ($ transparent || $ ignore ) {
5000
+ $ expected_answer = 42 ;
5001
+ $ expected_pi = 3.14 ;
5002
+ } else {
5003
+ $ expected_answer = false ;
5004
+ $ expected_pi = false ;
5005
+ }
5006
+
5007
+ $ this ->assertTrue ($ this ->redis ->set ('answer ' , 32 ));
5008
+ $ this ->assertEquals ($ expected_answer , $ this ->redis ->incr ('answer ' , 10 ));
5009
+
5010
+ $ this ->assertTrue ($ this ->redis ->set ('pi ' , 3.04 ));
5011
+ $ this ->assertEquals ($ expected_pi , $ this ->redis ->incrByFloat ('pi ' , 0.1 ));
5012
+
5013
+ $ this ->assertEquals (1 , $ this ->redis ->hset ('hash ' , 'answer ' , 32 ));
5014
+ $ this ->assertEquals ($ expected_answer , $ this ->redis ->hIncrBy ('hash ' , 'answer ' , 10 ));
5015
+
5016
+ $ this ->assertEquals (1 , $ this ->redis ->hset ('hash ' , 'pi ' , 3.04 ));
5017
+ $ this ->assertEquals ($ expected_pi , $ this ->redis ->hIncrByFloat ('hash ' , 'pi ' , 0.1 ));
5018
+ }
5019
+
5020
+ $ this ->redis ->setOption (Redis::OPT_SERIALIZER , Redis::SERIALIZER_NONE );
5021
+ $ this ->redis ->setOption (Redis::OPT_COMPRESSION , Redis::COMPRESSION_NONE );
5022
+ $ this ->redis ->setOption (Redis::OPT_PACK_IGNORE_NUMBERS , false );
5023
+ }
5024
+
5025
+ function testIgnoreNumbersReturnTypes () {
5026
+ $ combinations = $ this ->cartesianProduct ([
5027
+ [false , true ],
5028
+ array_filter ($ this ->getSerializers (), function ($ s ) {
5029
+ return $ s !== Redis::SERIALIZER_NONE ;
5030
+ }),
5031
+ array_filter ($ this ->getCompressors (), function ($ c ) {
5032
+ return $ c !== Redis::COMPRESSION_NONE ;
5033
+ }),
5034
+ ]);
5035
+
5036
+ foreach ($ combinations as [$ ignore , $ serializer , $ compression ]) {
5037
+ $ this ->redis ->setOption (Redis::OPT_PACK_IGNORE_NUMBERS , $ ignore );
5038
+ $ this ->redis ->setOption (Redis::OPT_SERIALIZER , $ serializer );
5039
+ $ this ->redis ->setOption (Redis::OPT_COMPRESSION , $ compression );
5040
+
5041
+ foreach ([42 , 3.14 ] as $ value ) {
5042
+ $ this ->assertTrue ($ this ->redis ->set ('key ' , $ value ));
5043
+
5044
+ /* There's a known issue in the PHP JSON parser, which
5045
+ can stringify numbers. Unclear the root cause */
5046
+ if ($ serializer == Redis::SERIALIZER_JSON ) {
5047
+ $ this ->assertEqualsWeak ($ value , $ this ->redis ->get ('key ' ));
5048
+ } else {
5049
+ $ this ->assertEquals ($ value , $ this ->redis ->get ('key ' ));
5050
+ }
5051
+ }
5052
+ }
5053
+
5054
+ $ this ->redis ->setOption (Redis::OPT_SERIALIZER , Redis::SERIALIZER_NONE );
5055
+ $ this ->redis ->setOption (Redis::OPT_COMPRESSION , Redis::COMPRESSION_NONE );
5056
+ $ this ->redis ->setOption (Redis::OPT_PACK_IGNORE_NUMBERS , false );
5057
+ }
5058
+
4961
5059
public function testSerializerIGBinary () {
4962
5060
if ( ! defined ('Redis::SERIALIZER_IGBINARY ' ))
4963
5061
$ this ->markTestSkipped ('Redis::SERIALIZER_IGBINARY is not defined ' );
0 commit comments