@@ -865,151 +865,156 @@ PHP_METHOD(RedisArray, select)
865865/* MGET will distribute the call to several nodes and regroup the values. */ 
866866PHP_METHOD (RedisArray , mget )
867867{
868- 	 zval  * object , * z_keys , z_argarray , * data , z_ret , * z_cur , z_tmp_array , * z_tmp ;
869- 	 int  i , j , n ;
870- 	 RedisArray  * ra ;
871- 	 int  * pos , argc , * argc_each ;
872- 	 HashTable  * h_keys ;
873- 	 zval  * * argv ;
868+      zval  * object , * z_keys , z_argarray , * data , z_ret , * z_cur , z_tmp_array , * z_tmp ;
869+      int  i , j , n ;
870+      RedisArray  * ra ;
871+      int  * pos , argc , * argc_each ;
872+      HashTable  * h_keys ;
873+      zval  * * argv ;
874874
875875    if  ((ra  =  redis_array_get (getThis () TSRMLS_CC )) ==  NULL ) {
876876        RETURN_FALSE ;
877877    }
878878
879- 	 /* Multi/exec support */ 
879+      /* Multi/exec support */ 
880880    HANDLE_MULTI_EXEC (ra , "MGET" );
881881
882- 	 if  (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
883- 				& object , redis_array_ce , & z_keys ) ==  FAILURE ) {
884- 		 RETURN_FALSE ;
885- 	 }
882+      if  (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
883+ 				      & object , redis_array_ce , & z_keys ) ==  FAILURE ) {
884+          RETURN_FALSE ;
885+      }
886886
887887
888- 	 /* init data structures */ 
889- 	 h_keys  =  Z_ARRVAL_P (z_keys );
890- 	 argc  =  zend_hash_num_elements (h_keys );
891- 	 argv  =  emalloc (argc  *  sizeof (zval * ));
892- 	 pos  =  emalloc (argc  *  sizeof (int ));
888+      /* init data structures */ 
889+      h_keys  =  Z_ARRVAL_P (z_keys );
890+      argc  =  zend_hash_num_elements (h_keys );
891+      argv  =  emalloc (argc  *  sizeof (zval * ));
892+      pos  =  emalloc (argc  *  sizeof (int ));
893893
894- 	 argc_each  =  emalloc (ra -> count  *  sizeof (int ));
895- 	 memset (argc_each , 0 , ra -> count  *  sizeof (int ));
894+      argc_each  =  emalloc (ra -> count  *  sizeof (int ));
895+      memset (argc_each , 0 , ra -> count  *  sizeof (int ));
896896
897- 	 /* associate each key to a redis node */ 
897+      /* associate each key to a redis node */ 
898898    i  =  0 ;
899899    ZEND_HASH_FOREACH_VAL (h_keys , data ) {
900- 	     /* If we need to represent a long key as a string */ 
901- 	     unsigned int   key_len ;
902- 	     char  kbuf [40 ], * key_lookup ;
903- 
904- 	     /* phpredis proper can only use string or long keys, so restrict to that here */ 
905- 	     if  (Z_TYPE_P (data ) !=  IS_STRING  &&  Z_TYPE_P (data ) !=  IS_LONG ) {
906- 	         php_error_docref (NULL  TSRMLS_CC , E_ERROR , "MGET: all keys must be strings or longs" );
907- 	         efree (argv );
908- 	         efree (pos );
909- 	         efree (argc_each );
910- 	         RETURN_FALSE ;
911- 	     }
912- 
913- 	     /* Convert to a string for hash lookup if it isn't one */ 
914- 	     if  (Z_TYPE_P (data ) ==  IS_STRING ) {
915- 	         key_len  =  Z_STRLEN_P (data );
900+          /* If we need to represent a long key as a string */ 
901+          unsigned int   key_len ;
902+          char  kbuf [40 ], * key_lookup ;
903+ 
904+          /* phpredis proper can only use string or long keys, so restrict to that here */ 
905+          if  (Z_TYPE_P (data ) !=  IS_STRING  &&  Z_TYPE_P (data ) !=  IS_LONG ) {
906+              php_error_docref (NULL  TSRMLS_CC , E_ERROR , "MGET: all keys must be strings or longs" );
907+              efree (argv );
908+              efree (pos );
909+              efree (argc_each );
910+              RETURN_FALSE ;
911+          }
912+ 
913+          /* Convert to a string for hash lookup if it isn't one */ 
914+          if  (Z_TYPE_P (data ) ==  IS_STRING ) {
915+              key_len  =  Z_STRLEN_P (data );
916916            key_lookup  =  Z_STRVAL_P (data );
917- 	     } else  {
918- 	         key_len  =  snprintf (kbuf , sizeof (kbuf ), "%ld" , Z_LVAL_P (data ));
919- 	         key_lookup  =  (char * )kbuf ;
920- 	     }
917+          } else  {
918+              key_len  =  snprintf (kbuf , sizeof (kbuf ), "%ld" , Z_LVAL_P (data ));
919+              key_lookup  =  (char * )kbuf ;
920+          }
921921
922- 		 /* Find our node */ 
922+          /* Find our node */ 
923923        if  (ra_find_node (ra , key_lookup , key_len , & pos [i ] TSRMLS_CC ) ==  NULL ) {
924924            /* TODO: handle */ 
925925        }
926926
927- 		 argc_each [pos [i ]]++ ;	/* count number of keys per node */ 
928- 		 argv [i ++ ] =  data ;
929- 	 } ZEND_HASH_FOREACH_END ();
927+          argc_each [pos [i ]]++ ;	/* count number of keys per node */ 
928+          argv [i ++ ] =  data ;
929+      } ZEND_HASH_FOREACH_END ();
930930
931- 	array_init (& z_tmp_array );
932- 	/* calls */ 
933- 	for (n  =  0 ; n  <  ra -> count ; ++ n ) { /* for each node */ 
934- 	    /* We don't even need to make a call to this node if no keys go there */ 
935- 	    if (!argc_each [n ]) continue ;
931+     array_init (& z_tmp_array );
936932
937- 	    /* copy args for MGET call on node. */ 
938- 		array_init (& z_argarray );
933+     /* calls */ 
934+     for (n  =  0 ; n  <  ra -> count ; ++ n ) { /* for each node */ 
935+         /* We don't even need to make a call to this node if no keys go there */ 
936+         if (!argc_each [n ]) continue ;
939937
940- 		for (i  =  0 ; i  <  argc ; ++ i ) {
941- 			if (pos [i ] !=  n ) continue ;
938+         /* copy args for MGET call on node. */ 
939+         array_init (& z_argarray );
940+ 
941+         for (i  =  0 ; i  <  argc ; ++ i ) {
942+             if (pos [i ] !=  n ) continue ;
942943
943944#if  (PHP_MAJOR_VERSION  <  7 )
944- 			 MAKE_STD_ZVAL (z_tmp );
945+              MAKE_STD_ZVAL (z_tmp );
945946#else 
946947            zval  zv ;
947948            z_tmp  =  & zv ;
948949#endif 
950+ 
949951            ZVAL_ZVAL (z_tmp , argv [i ], 1 , 0 );
950- 			 add_next_index_zval (& z_argarray , z_tmp );
951- 		 }
952+              add_next_index_zval (& z_argarray , z_tmp );
953+          }
952954
953955        zval  z_fun ;
954956        /* prepare call */ 
955957        ZVAL_STRINGL (& z_fun , "MGET" , 4 );
956- 		/* call MGET on the node */ 
958+ 
959+         /* call MGET on the node */ 
957960        call_user_function (& redis_ce -> function_table , & ra -> redis [n ], & z_fun , & z_ret , 1 , & z_argarray );
958961        zval_dtor (& z_fun );
959962
960- 		 /* cleanup args array */ 
961- 		 zval_dtor (& z_argarray );
963+          /* cleanup args array */ 
964+          zval_dtor (& z_argarray );
962965
963966        /* Error out if we didn't get a proper response */ 
964967        if  (Z_TYPE (z_ret ) !=  IS_ARRAY ) {
965968            /* cleanup */ 
966969            zval_dtor (& z_ret );
967970            zval_dtor (& z_tmp_array );
968- 	         efree (argv );
971+ 	    efree (argv );
969972            efree (pos );
970973            efree (argc_each );
971974
972975            /* failure */ 
973976            RETURN_FALSE ;
974977        }
975978
976- 		 for (i  =  0 , j  =  0 ; i  <  argc ; ++ i ) {
977- 		     if (pos [i ] !=  n ) continue ;
979+          for (i  =  0 , j  =  0 ; i  <  argc ; ++ i ) {
980+              if (pos [i ] !=  n ) continue ;
978981
979- 			 z_cur  =  zend_hash_index_find (Z_ARRVAL (z_ret ), j ++ );
982+              z_cur  =  zend_hash_index_find (Z_ARRVAL (z_ret ), j ++ );
980983
981984#if  (PHP_MAJOR_VERSION  <  7 )
982- 			 MAKE_STD_ZVAL (z_tmp );
985+              MAKE_STD_ZVAL (z_tmp );
983986#else 
984987            zval  zv ;
985988            z_tmp  =  & zv ;
986989#endif 
987990            ZVAL_ZVAL (z_tmp , z_cur , 1 , 0 );
988- 			add_index_zval (& z_tmp_array , i , z_tmp );
989- 		}
990- 		zval_dtor (& z_ret );
991- 	}
991+             add_index_zval (& z_tmp_array , i , z_tmp );
992+         }
992993
993- 	array_init (return_value );
994- 	/* copy temp array in the right order to return_value */ 
995- 	for (i  =  0 ; i  <  argc ; ++ i ) {
996- 		z_cur  =  zend_hash_index_find (Z_ARRVAL (z_tmp_array ), i );
994+         zval_dtor (& z_ret );
995+     }
996+ 
997+     array_init (return_value );
998+     /* copy temp array in the right order to return_value */ 
999+     for (i  =  0 ; i  <  argc ; ++ i ) {
1000+         z_cur  =  zend_hash_index_find (Z_ARRVAL (z_tmp_array ), i );
9971001
9981002#if  (PHP_MAJOR_VERSION  <  7 )
999- 		 MAKE_STD_ZVAL (z_tmp );
1003+          MAKE_STD_ZVAL (z_tmp );
10001004#else 
10011005        zval  zv ;
10021006        z_tmp  =  & zv ;
10031007#endif 
1008+ 
10041009        ZVAL_ZVAL (z_tmp , z_cur , 1 , 0 );
1005- 		 add_next_index_zval (return_value , z_tmp );
1006- 	 }
1010+          add_next_index_zval (return_value , z_tmp );
1011+      }
10071012
1008- 	 /* cleanup */ 
1009- 	 zval_dtor (& z_tmp_array );
1010- 	 efree (argv );
1011- 	 efree (pos );
1012- 	 efree (argc_each );
1013+      /* cleanup */ 
1014+      zval_dtor (& z_tmp_array );
1015+      efree (argv );
1016+      efree (pos );
1017+      efree (argc_each );
10131018}
10141019
10151020
0 commit comments