@@ -1860,7 +1860,7 @@ public function testZX() {
18601860 $ this ->redis ->delete ('z ' );
18611861 $ this ->redis ->zadd ('z ' , 1 , 'one ' );
18621862 $ this ->redis ->zadd ('z ' , 2 , 'two ' );
1863- $ this ->redis ->zadd ('z ' , 5 , 'five ' );
1863+ $ this ->redis ->zadd ('z ' , 5 , 'five ' );
18641864
18651865 $ this ->assertTrue (0 === $ this ->redis ->zRank ('z ' , 'one ' ));
18661866 $ this ->assertTrue (1 === $ this ->redis ->zRank ('z ' , 'two ' ));
@@ -2921,29 +2921,29 @@ public function testGetLastError() {
29212921 $ this ->assertTrue (strlen ($ this ->redis ->getLastError ()) > 0 );
29222922 }
29232923
2924- // Helper function to compare nested results -- from the php.net array_diff page, I believe
2925- private function array_diff_recursive ($ aArray1 , $ aArray2 ) {
2926- $ aReturn = array ();
2927-
2928- foreach ($ aArray1 as $ mKey => $ mValue ) {
2929- if (array_key_exists ($ mKey , $ aArray2 )) {
2930- if (is_array ($ mValue )) {
2931- $ aRecursiveDiff = $ this ->array_diff_recursive ($ mValue , $ aArray2 [$ mKey ]);
2932- if (count ($ aRecursiveDiff )) {
2933- $ aReturn [$ mKey ] = $ aRecursiveDiff ;
2934- }
2935- } else {
2936- if ($ mValue != $ aArray2 [$ mKey ]) {
2937- $ aReturn [$ mKey ] = $ mValue ;
2938- }
2939- }
2940- } else {
2941- $ aReturn [$ mKey ] = $ mValue ;
2942- }
2943- }
2944-
2945- return $ aReturn ;
2946- }
2924+ // Helper function to compare nested results -- from the php.net array_diff page, I believe
2925+ private function array_diff_recursive ($ aArray1 , $ aArray2 ) {
2926+ $ aReturn = array ();
2927+
2928+ foreach ($ aArray1 as $ mKey => $ mValue ) {
2929+ if (array_key_exists ($ mKey , $ aArray2 )) {
2930+ if (is_array ($ mValue )) {
2931+ $ aRecursiveDiff = $ this ->array_diff_recursive ($ mValue , $ aArray2 [$ mKey ]);
2932+ if (count ($ aRecursiveDiff )) {
2933+ $ aReturn [$ mKey ] = $ aRecursiveDiff ;
2934+ }
2935+ } else {
2936+ if ($ mValue != $ aArray2 [$ mKey ]) {
2937+ $ aReturn [$ mKey ] = $ mValue ;
2938+ }
2939+ }
2940+ } else {
2941+ $ aReturn [$ mKey ] = $ mValue ;
2942+ }
2943+ }
2944+
2945+ return $ aReturn ;
2946+ }
29472947
29482948 public function testScript () {
29492949 // Flush any scripts we have
@@ -3114,9 +3114,9 @@ public function testUnserialize() {
31143114
31153115 // Pass them through redis so they're serialized
31163116 foreach ($ vals as $ key => $ val ) {
3117- $ this ->redis ->setOption (Redis::OPT_SERIALIZER , $ mode );
3117+ $ this ->redis ->setOption (Redis::OPT_SERIALIZER , $ mode );
31183118
3119- $ key = "key " . ++$ key ;
3119+ $ key = "key " . ++$ key ;
31203120 $ this ->redis ->del ($ key );
31213121 $ this ->redis ->set ($ key , $ val );
31223122
@@ -3148,6 +3148,35 @@ public function testPrefix() {
31483148 $ this ->redis ->setOption (Redis::OPT_PREFIX , '' );
31493149
31503150 }
3151+
3152+ public function testReconnectSelect () {
3153+ $ key = 'reconnect-select ' ;
3154+ $ value = 'Has been set! ' ;
3155+
3156+ $ original_cfg = $ this ->redis ->config ('GET ' , 'timeout ' );
3157+
3158+ // Make sure the default DB doesn't have the key.
3159+ $ this ->redis ->select (0 );
3160+ $ this ->redis ->delete ($ key );
3161+
3162+ // Set the key on a different DB.
3163+ $ this ->redis ->select (5 );
3164+ $ this ->redis ->set ($ key , $ value );
3165+
3166+ // Time out after 1 second.
3167+ $ this ->redis ->config ('SET ' , 'timeout ' , '1 ' );
3168+
3169+ // Wait for the timeout. With Redis 2.4, we have to wait up to 10 s
3170+ // for the server to close the connection, regardless of the timeout
3171+ // setting.
3172+ sleep (11 );
3173+
3174+ // Make sure we're still using the same DB.
3175+ $ this ->assertEquals ($ value , $ this ->redis ->get ($ key ));
3176+
3177+ // Revert the setting.
3178+ $ this ->redis ->config ('SET ' , 'timeout ' , $ original_cfg ['timeout ' ]);
3179+ }
31513180}
31523181
31533182TestSuite::run ("Redis_Test " );
0 commit comments