@@ -36,7 +36,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC)
3636 int count = zend_hash_num_elements (hosts );
3737 char * host , * p ;
3838 short port ;
39- zval * * zpData , z_cons , z_ret ;
39+ zval * * zpData , * z_args , z_cons , z_ret ;
4040 RedisSock * redis_sock = NULL ;
4141
4242 /* function calls on the Redis object */
@@ -59,7 +59,9 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC)
5959 if ((p = strchr (host , ':' ))) { /* found port */
6060 host_len = p - host ;
6161 port = (short )atoi (p + 1 );
62- }
62+ } else if (strchr (host ,'/' ) != NULL ) { /* unix socket */
63+ port = -1 ;
64+ }
6365
6466 /* create Redis object */
6567 MAKE_STD_ZVAL (ra -> redis [i ]);
@@ -68,7 +70,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC)
6870 call_user_function (& redis_ce -> function_table , & ra -> redis [i ], & z_cons , & z_ret , 0 , NULL TSRMLS_CC );
6971
7072 /* create socket */
71- redis_sock = redis_sock_create (host , host_len , port , 0 , 0 , NULL , retry_interval ); /* TODO: persistence? */
73+ redis_sock = redis_sock_create (host , host_len , port , 0 , ra -> pconnect , NULL , retry_interval );
7274
7375 /* connect */
7476 redis_sock_server_open (redis_sock , 1 TSRMLS_CC );
@@ -160,9 +162,10 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
160162 zval * z_params_index ;
161163 zval * z_params_autorehash ;
162164 zval * z_params_retry_interval ;
165+ zval * z_params_pconnect ;
163166 RedisArray * ra = NULL ;
164167
165- zend_bool b_index = 0 , b_autorehash = 0 ;
168+ zend_bool b_index = 0 , b_autorehash = 0 , b_pconnect = 0 ;
166169 long l_retry_interval = 0 ;
167170 HashTable * hHosts = NULL , * hPrev = NULL ;
168171
@@ -241,8 +244,18 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
241244 }
242245 }
243246
247+ /* find pconnect option */
248+ MAKE_STD_ZVAL (z_params_pconnect );
249+ array_init (z_params_pconnect );
250+ sapi_module .treat_data (PARSE_STRING , estrdup (INI_STR ("redis.arrays.pconnect" )), z_params_pconnect TSRMLS_CC );
251+ if (zend_hash_find (Z_ARRVAL_P (z_params_pconnect ), name , strlen (name ) + 1 , (void * * ) & z_data_pp ) != FAILURE ) {
252+ if (Z_TYPE_PP (z_data_pp ) == IS_STRING && strncmp (Z_STRVAL_PP (z_data_pp ), "1" , 1 ) == 0 ) {
253+ b_pconnect = 1 ;
254+ }
255+ }
256+
244257 /* create RedisArray object */
245- ra = ra_make_array (hHosts , z_fun , z_dist , hPrev , b_index , l_retry_interval TSRMLS_CC );
258+ ra = ra_make_array (hHosts , z_fun , z_dist , hPrev , b_index , l_retry_interval , b_pconnect TSRMLS_CC );
246259 ra -> auto_rehash = b_autorehash ;
247260
248261 /* cleanup */
@@ -258,12 +271,14 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
258271 efree (z_params_autorehash );
259272 zval_dtor (z_params_retry_interval );
260273 efree (z_params_retry_interval );
274+ zval_dtor (z_params_pconnect );
275+ efree (z_params_pconnect );
261276
262277 return ra ;
263278}
264279
265280RedisArray *
266- ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , HashTable * hosts_prev , zend_bool b_index , long retry_interval TSRMLS_DC ) {
281+ ra_make_array (HashTable * hosts , zval * z_fun , zval * z_dist , HashTable * hosts_prev , zend_bool b_index , long retry_interval , zend_bool b_pconnect TSRMLS_DC ) {
267282
268283 int count = zend_hash_num_elements (hosts );
269284
@@ -284,7 +299,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
284299 if (NULL == ra_load_hosts (ra , hosts , retry_interval TSRMLS_CC )) {
285300 return NULL ;
286301 }
287- ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , retry_interval TSRMLS_CC ) : NULL ;
302+ ra -> prev = hosts_prev ? ra_make_array (hosts_prev , z_fun , z_dist , NULL , b_index , retry_interval , b_pconnect TSRMLS_CC ) : NULL ;
288303
289304 /* copy function if provided */
290305 if (z_fun ) {
0 commit comments