diff options
Diffstat (limited to 'redis_array_impl.c')
-rw-r--r-- | redis_array_impl.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/redis_array_impl.c b/redis_array_impl.c index c38e2fe6..f804f475 100644 --- a/redis_array_impl.c +++ b/redis_array_impl.c @@ -29,7 +29,7 @@ extern int le_redis_sock; extern zend_class_entry *redis_ce; RedisArray* -ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC) +ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool lazy_connect TSRMLS_DC) { int i, host_len, id; int count = zend_hash_num_elements(hosts); @@ -67,10 +67,13 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC) call_user_function(&redis_ce->function_table, &ra->redis[i], &z_cons, &z_ret, 0, NULL TSRMLS_CC); /* create socket */ - redis_sock = redis_sock_create(host, host_len, port, 0, 0, NULL, retry_interval); /* TODO: persistence? */ + redis_sock = redis_sock_create(host, host_len, port, 0, 0, NULL, retry_interval, lazy_connect); /* TODO: persistence? */ - /* connect */ - redis_sock_server_open(redis_sock, 1 TSRMLS_CC); + if (!lazy_connect) + { + /* connect */ + redis_sock_server_open(redis_sock, 1 TSRMLS_CC); + } /* attach */ #if PHP_VERSION_ID >= 50400 @@ -159,10 +162,12 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { zval *z_params_index; zval *z_params_autorehash; zval *z_params_retry_interval; + zval *z_params_lazy_connect; RedisArray *ra = NULL; zend_bool b_index = 0, b_autorehash = 0; long l_retry_interval = 0; + zend_bool b_lazy_connect = 0; HashTable *hHosts = NULL, *hPrev = NULL; /* find entry */ @@ -240,8 +245,18 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { } } + /* find retry interval option */ + MAKE_STD_ZVAL(z_params_lazy_connect); + array_init(z_params_lazy_connect); + sapi_module.treat_data(PARSE_STRING, estrdup(INI_STR("redis.arrays.lazyconnect")), z_params_lazy_connect TSRMLS_CC); + if (zend_hash_find(Z_ARRVAL_P(z_params_lazy_connect), name, strlen(name) + 1, (void **) &z_data_pp) != FAILURE) { + if(Z_TYPE_PP(z_data_pp) == IS_STRING && strncmp(Z_STRVAL_PP(z_data_pp), "1", 1) == 0) { + b_lazy_connect = 1; + } + } + /* create RedisArray object */ - ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index, l_retry_interval TSRMLS_CC); + ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index, l_retry_interval, b_lazy_connect TSRMLS_CC); ra->auto_rehash = b_autorehash; /* cleanup */ @@ -257,12 +272,14 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { efree(z_params_autorehash); zval_dtor(z_params_retry_interval); efree(z_params_retry_interval); + zval_dtor(z_params_lazy_connect); + efree(z_params_lazy_connect); return ra; } RedisArray * -ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, long retry_interval TSRMLS_DC) { +ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, long retry_interval, zend_bool lazy_connect TSRMLS_DC) { int count = zend_hash_num_elements(hosts); @@ -280,10 +297,10 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev /* init array data structures */ ra_init_function_table(ra); - if(NULL == ra_load_hosts(ra, hosts, retry_interval TSRMLS_CC)) { + if(NULL == ra_load_hosts(ra, hosts, retry_interval, lazy_connect TSRMLS_CC)) { return NULL; } - ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, retry_interval TSRMLS_CC) : NULL; + ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, retry_interval, lazy_connect TSRMLS_CC) : NULL; /* copy function if provided */ if(z_fun) { |