@@ -161,7 +161,7 @@ ra_find_name(const char *name) {
161161/* laod array from INI settings */
162162RedisArray * ra_load_array (const char * name TSRMLS_DC ) {
163163
164- zval * z_data , z_fun , z_dist , z_algo ;
164+ zval * z_data , z_fun , z_dist ;
165165 zval z_params_hosts ;
166166 zval z_params_prev ;
167167 zval z_params_funs ;
@@ -177,6 +177,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
177177 zval z_params_consistent ;
178178 RedisArray * ra = NULL ;
179179
180+ zend_string * algorithm = NULL ;
180181 zend_bool b_index = 0 , b_autorehash = 0 , b_pconnect = 0 , consistent = 0 ;
181182 long l_retry_interval = 0 ;
182183 zend_bool b_lazy_connect = 0 ;
@@ -232,9 +233,8 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
232233 if ((iptr = INI_STR ("redis.arrays.algorithm" )) != NULL ) {
233234 sapi_module .treat_data (PARSE_STRING , estrdup (iptr ), & z_params_algo TSRMLS_CC );
234235 }
235- ZVAL_NULL (& z_algo );
236236 if ((z_data = zend_hash_str_find (Z_ARRVAL (z_params_algo ), name , name_len )) != NULL ) {
237- ZVAL_ZVAL ( & z_algo , z_data , 1 , 0 );
237+ algorithm = zval_get_string ( z_data );
238238 }
239239
240240 /* find index option */
@@ -337,13 +337,15 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
337337
338338
339339 /* create RedisArray object */
340- ra = ra_make_array (hHosts , & z_fun , & z_dist , & z_algo , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect , d_connect_timeout , read_timeout , consistent TSRMLS_CC );
340+ ra = ra_make_array (hHosts , & z_fun , & z_dist , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect , d_connect_timeout , read_timeout , consistent , algorithm TSRMLS_CC );
341341 if (ra ) {
342342 ra -> auto_rehash = b_autorehash ;
343343 if (ra -> prev ) ra -> prev -> auto_rehash = b_autorehash ;
344344 }
345345
346346 /* cleanup */
347+ if (algorithm ) zend_string_release (algorithm );
348+
347349 zval_dtor (& z_params_hosts );
348350 zval_dtor (& z_params_prev );
349351 zval_dtor (& z_params_funs );
@@ -357,7 +359,6 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
357359 zval_dtor (& z_params_read_timeout );
358360 zval_dtor (& z_params_lazy_connect );
359361 zval_dtor (& z_params_consistent );
360- zval_dtor (& z_algo );
361362 zval_dtor (& z_dist );
362363 zval_dtor (& z_fun );
363364
@@ -405,7 +406,7 @@ ra_make_continuum(zend_string **hosts, int nb_hosts)
405406}
406407
407408RedisArray *
408- ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , zval * z_algo , HashTable * hosts_prev , zend_bool b_index , zend_bool b_pconnect , long retry_interval , zend_bool b_lazy_connect , double connect_timeout , double read_timeout , zend_bool consistent TSRMLS_DC ) {
409+ ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , HashTable * hosts_prev , zend_bool b_index , zend_bool b_pconnect , long retry_interval , zend_bool b_lazy_connect , double connect_timeout , double read_timeout , zend_bool consistent , zend_string * algorithm TSRMLS_DC ) {
409410
410411 int i , count ;
411412 RedisArray * ra ;
@@ -415,7 +416,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
415416 /* create object */
416417 ra = emalloc (sizeof (RedisArray ));
417418 ra -> hosts = ecalloc (count , sizeof (* ra -> hosts ));
418- ra -> redis = ecalloc (count , sizeof (zval ));
419+ ra -> redis = ecalloc (count , sizeof (* ra -> redis ));
419420 ra -> count = 0 ;
420421 ra -> z_multi_exec = NULL ;
421422 ra -> index = b_index ;
@@ -424,6 +425,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
424425 ra -> connect_timeout = connect_timeout ;
425426 ra -> read_timeout = read_timeout ;
426427 ra -> continuum = NULL ;
428+ ra -> algorithm = NULL ;
427429
428430 if (ra_load_hosts (ra , hosts , retry_interval , b_lazy_connect TSRMLS_CC ) == NULL || !ra -> count ) {
429431 for (i = 0 ; i < ra -> count ; ++ i ) {
@@ -435,15 +437,15 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab
435437 efree (ra );
436438 return NULL ;
437439 }
438- ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , z_algo , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect , connect_timeout , read_timeout , consistent TSRMLS_CC ) : NULL ;
440+ ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect , connect_timeout , read_timeout , consistent , algorithm TSRMLS_CC ) : NULL ;
439441
440442 /* init array data structures */
441443 ra_init_function_table (ra );
442444
443445 /* Set hash function and distribtor if provided */
444446 ZVAL_ZVAL (& ra -> z_fun , z_fun , 1 , 0 );
445447 ZVAL_ZVAL (& ra -> z_dist , z_dist , 1 , 0 );
446- ZVAL_ZVAL ( & ra -> z_algo , z_algo , 1 , 0 );
448+ if ( algorithm ) ra -> algorithm = zend_string_copy ( algorithm );
447449
448450 /* init continuum */
449451 if (consistent ) {
@@ -537,7 +539,7 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
537539 const php_hash_ops * ops ;
538540
539541 /* hash */
540- if (Z_TYPE ( ra -> z_algo ) == IS_STRING && (ops = php_hash_fetch_ops (Z_STRVAL (ra -> z_algo ), Z_STRLEN (ra -> z_algo ))) != NULL ) {
542+ if (ra -> algorithm && (ops = php_hash_fetch_ops (ZSTR_VAL (ra -> algorithm ), ZSTR_LEN (ra -> algorithm ))) != NULL ) {
541543 void * ctx = emalloc (ops -> context_size );
542544 unsigned char * digest = emalloc (ops -> digest_size );
543545
0 commit comments