@@ -1083,6 +1083,61 @@ public function testsRandMember() {
10831083 }
10841084 }
10851085
1086+ public function testSRandMemberWithCount () {
1087+ // Make sure the set is nuked
1088+ $ this ->redis ->delete ('set0 ' );
1089+
1090+ // Run with a count (positive and negative) on an empty set
1091+ $ ret_pos = $ this ->redis ->sRandMember ('set0 ' , 10 );
1092+ $ ret_neg = $ this ->redis ->sRandMember ('set0 ' , -10 );
1093+
1094+ // Should both be empty arrays
1095+ $ this ->assertTrue (is_array ($ ret_pos ) && empty ($ ret_pos ));
1096+ $ this ->assertTrue (is_array ($ ret_neg ) && empty ($ ret_neg ));
1097+
1098+ // Add a few items to the set
1099+ for ($ i =0 ;$ i <100 ;$ i ++) {
1100+ $ this ->redis ->sadd ('set0 ' , "member $ i " );
1101+ }
1102+
1103+ // Get less than the size of the list
1104+ $ ret_slice = $ this ->redis ->srandmember ('set0 ' , 20 );
1105+
1106+ // Should be an array with 20 items
1107+ $ this ->assertTrue (is_array ($ ret_slice ) && count ($ ret_slice ) == 20 );
1108+
1109+ // Ask for more items than are in the list (but with a positive count)
1110+ $ ret_slice = $ this ->redis ->srandmember ('set0 ' , 200 );
1111+
1112+ // Should be an array, should be however big the set is, exactly
1113+ $ this ->assertTrue (is_array ($ ret_slice ) && count ($ ret_slice ) == $ i );
1114+
1115+ // Now ask for too many items but negative
1116+ $ ret_slice = $ this ->redis ->srandmember ('set0 ' , -200 );
1117+
1118+ // Should be an array, should have exactly the # of items we asked for (will be dups)
1119+ $ this ->assertTrue (is_array ($ ret_slice ) && count ($ ret_slice ) == 200 );
1120+
1121+ //
1122+ // Test in a pipeline
1123+ //
1124+
1125+ $ pipe = $ this ->redis ->pipeline ();
1126+
1127+ $ pipe ->srandmember ('set0 ' , 20 );
1128+ $ pipe ->srandmember ('set0 ' , 200 );
1129+ $ pipe ->srandmember ('set0 ' , -200 );
1130+
1131+ $ ret = $ this ->redis ->exec ();
1132+
1133+ $ this ->assertTrue (is_array ($ ret [0 ]) && count ($ ret [0 ]) == 20 );
1134+ $ this ->assertTrue (is_array ($ ret [1 ]) && count ($ ret [1 ]) == $ i );
1135+ $ this ->assertTrue (is_array ($ ret [2 ]) && count ($ ret [2 ]) == 200 );
1136+
1137+ // Kill the set
1138+ $ this ->redis ->del ('set0 ' );
1139+ }
1140+
10861141 public function testsContains ()
10871142 {
10881143 $ this ->redis ->delete ('set ' );
@@ -3263,8 +3318,10 @@ public function testUnserialize() {
32633318 1 ,1.5 ,'one ' ,Array ('this ' ,'is ' ,'an ' ,'array ' )
32643319 );
32653320
3266- $ serializers = Array (Redis::SERIALIZER_PHP );
3267- if (defined ('Redis::SERIALIZER_IGBINARY ' )) $ serializers [] = Redis::SERIALIZER_IGBINARY ;
3321+ $ serializers = Array (Redis::SERIALIZER_PHP );
3322+ if (defined ('Redis::SERIALIZER_IGBINARY ' )) {
3323+ $ serializers [] = Redis::SERIALIZER_IGBINARY ;
3324+ }
32683325
32693326 foreach ($ serializers as $ mode ) {
32703327 $ vals_enc = Array ();
0 commit comments