@@ -70,7 +70,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
70
70
call_user_function (& redis_ce -> function_table , & ra -> redis [i ], & z_cons , & z_ret , 0 , NULL TSRMLS_CC );
71
71
72
72
/* create socket */
73
- redis_sock = redis_sock_create (host , host_len , port , 0 , ra -> pconnect , NULL , retry_interval , b_lazy_connect );
73
+ redis_sock = redis_sock_create (host , host_len , port , ra -> connect_timeout , ra -> pconnect , NULL , retry_interval , b_lazy_connect );
74
74
75
75
if (!b_lazy_connect )
76
76
{
@@ -166,12 +166,14 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
166
166
zval * z_params_autorehash ;
167
167
zval * z_params_retry_interval ;
168
168
zval * z_params_pconnect ;
169
+ zval * z_params_connect_timeout ;
169
170
zval * z_params_lazy_connect ;
170
171
RedisArray * ra = NULL ;
171
172
172
173
zend_bool b_index = 0 , b_autorehash = 0 , b_pconnect = 0 ;
173
174
long l_retry_interval = 0 ;
174
175
zend_bool b_lazy_connect = 0 ;
176
+ double d_connect_timeout = 0 ;
175
177
HashTable * hHosts = NULL , * hPrev = NULL ;
176
178
177
179
/* find entry */
@@ -258,18 +260,34 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
258
260
b_pconnect = 1 ;
259
261
}
260
262
}
261
- /* find retry interval option */
263
+
264
+ /* find lazy connect option */
262
265
MAKE_STD_ZVAL (z_params_lazy_connect );
263
266
array_init (z_params_lazy_connect );
264
267
sapi_module .treat_data (PARSE_STRING , estrdup (INI_STR ("redis.arrays.lazyconnect" )), z_params_lazy_connect TSRMLS_CC );
265
268
if (zend_hash_find (Z_ARRVAL_P (z_params_lazy_connect ), name , strlen (name ) + 1 , (void * * ) & z_data_pp ) != FAILURE ) {
266
269
if (Z_TYPE_PP (z_data_pp ) == IS_STRING && strncmp (Z_STRVAL_PP (z_data_pp ), "1" , 1 ) == 0 ) {
267
- b_lazy_connect = 1 ;
270
+ b_lazy_connect = 1 ;
271
+ }
272
+ }
273
+
274
+ /* find connect timeout option */
275
+ MAKE_STD_ZVAL (z_params_connect_timeout );
276
+ array_init (z_params_connect_timeout );
277
+ sapi_module .treat_data (PARSE_STRING , estrdup (INI_STR ("redis.arrays.connecttimeout" )), z_params_connect_timeout TSRMLS_CC );
278
+ if (zend_hash_find (Z_ARRVAL_P (z_params_connect_timeout ), name , strlen (name ) + 1 , (void * * ) & z_data_pp ) != FAILURE ) {
279
+ if (Z_TYPE_PP (z_data_pp ) == IS_DOUBLE || Z_TYPE_PP (z_data_pp ) == IS_STRING ) {
280
+ if (Z_TYPE_PP (z_data_pp ) == IS_DOUBLE ) {
281
+ d_connect_timeout = Z_DVAL_PP (z_data_pp );
282
+ }
283
+ else {
284
+ d_connect_timeout = atof (Z_STRVAL_PP (z_data_pp ));
285
+ }
268
286
}
269
287
}
270
-
288
+
271
289
/* create RedisArray object */
272
- ra = ra_make_array (hHosts , z_fun , z_dist , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect TSRMLS_CC );
290
+ ra = ra_make_array (hHosts , z_fun , z_dist , hPrev , b_index , b_pconnect , l_retry_interval , b_lazy_connect , d_connect_timeout TSRMLS_CC );
273
291
ra -> auto_rehash = b_autorehash ;
274
292
275
293
/* cleanup */
@@ -287,14 +305,16 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
287
305
efree (z_params_retry_interval );
288
306
zval_dtor (z_params_pconnect );
289
307
efree (z_params_pconnect );
308
+ zval_dtor (z_params_connect_timeout );
309
+ efree (z_params_connect_timeout );
290
310
zval_dtor (z_params_lazy_connect );
291
311
efree (z_params_lazy_connect );
292
312
293
313
return ra ;
294
314
}
295
315
296
316
RedisArray *
297
- 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 TSRMLS_DC ) {
317
+ 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 TSRMLS_DC ) {
298
318
299
319
int count = zend_hash_num_elements (hosts );
300
320
@@ -309,14 +329,15 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
309
329
ra -> index = b_index ;
310
330
ra -> auto_rehash = 0 ;
311
331
ra -> pconnect = b_pconnect ;
332
+ ra -> connect_timeout = connect_timeout ;
312
333
313
334
/* init array data structures */
314
335
ra_init_function_table (ra );
315
336
316
337
if (NULL == ra_load_hosts (ra , hosts , retry_interval , b_lazy_connect TSRMLS_CC )) {
317
338
return NULL ;
318
339
}
319
- ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , b_pconnect , retry_interval , b_lazy_connect TSRMLS_CC ) : NULL ;
340
+ 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 TSRMLS_CC ) : NULL ;
320
341
321
342
/* copy function if provided */
322
343
if (z_fun ) {
0 commit comments