Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee571ea

Browse files
Merge branch 'feature/ra-performance' into develop
2 parents 2099f19 + 16185f2 commit ee571ea

File tree

5 files changed

+102
-12
lines changed

5 files changed

+102
-12
lines changed

config.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* config.h. Generated from config.h.in by configure. */
2+
/* config.h.in. Generated from configure.in by autoheader. */
3+
4+
/* Whether to build redis as dynamic module */
5+
#define COMPILE_DL_REDIS 1
6+
7+
/* Define to 1 if you have the <dlfcn.h> header file. */
8+
#define HAVE_DLFCN_H 1
9+
10+
/* Define to 1 if you have the <inttypes.h> header file. */
11+
#define HAVE_INTTYPES_H 1
12+
13+
/* Define to 1 if you have the <memory.h> header file. */
14+
#define HAVE_MEMORY_H 1
15+
16+
/* Whether redis igbinary serializer is enabled */
17+
/* #undef HAVE_REDIS_IGBINARY */
18+
19+
/* Define to 1 if you have the <stdint.h> header file. */
20+
#define HAVE_STDINT_H 1
21+
22+
/* Define to 1 if you have the <stdlib.h> header file. */
23+
#define HAVE_STDLIB_H 1
24+
25+
/* Define to 1 if you have the <strings.h> header file. */
26+
#define HAVE_STRINGS_H 1
27+
28+
/* Define to 1 if you have the <string.h> header file. */
29+
#define HAVE_STRING_H 1
30+
31+
/* Define to 1 if you have the <sys/stat.h> header file. */
32+
#define HAVE_SYS_STAT_H 1
33+
34+
/* Define to 1 if you have the <sys/types.h> header file. */
35+
#define HAVE_SYS_TYPES_H 1
36+
37+
/* Define to 1 if you have the <unistd.h> header file. */
38+
#define HAVE_UNISTD_H 1
39+
40+
/* Define to the sub-directory in which libtool stores uninstalled libraries.
41+
*/
42+
#define LT_OBJDIR ".libs/"
43+
44+
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
45+
/* #undef NO_MINUS_C_MINUS_O */
46+
47+
/* Define to the address where bug reports for this package should be sent. */
48+
#define PACKAGE_BUGREPORT ""
49+
50+
/* Define to the full name of this package. */
51+
#define PACKAGE_NAME ""
52+
53+
/* Define to the full name and version of this package. */
54+
#define PACKAGE_STRING ""
55+
56+
/* Define to the one symbol short name of this package. */
57+
#define PACKAGE_TARNAME ""
58+
59+
/* Define to the home page for this package. */
60+
#define PACKAGE_URL ""
61+
62+
/* Define to the version of this package. */
63+
#define PACKAGE_VERSION ""
64+
65+
/* redis sessions */
66+
#define PHP_SESSION 1
67+
68+
/* Define to 1 if you have the ANSI C header files. */
69+
#define STDC_HEADERS 1

redis_array.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ PHP_METHOD(RedisArray, __construct)
194194
zval *z0, *z_fun = NULL, *z_dist = NULL, **zpData, *z_opts = NULL;
195195
int id;
196196
RedisArray *ra = NULL;
197-
zend_bool b_index = 0, b_autorehash = 0;
197+
zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
198198
HashTable *hPrev = NULL, *hOpts = NULL;
199199
long l_retry_interval = 0;
200200

@@ -238,9 +238,14 @@ PHP_METHOD(RedisArray, __construct)
238238
b_autorehash = Z_BVAL_PP(zpData);
239239
}
240240

241+
/* pconnect */
242+
if(FAILURE != zend_hash_find(hOpts, "pconnect", sizeof("pconnect"), (void**)&zpData) && Z_TYPE_PP(zpData) == IS_BOOL) {
243+
b_pconnect = Z_BVAL_PP(zpData);
244+
}
245+
241246
/* extract retry_interval option. */
242-
zval **z_retry_interval_pp;
243-
if (FAILURE != zend_hash_find(hOpts, "retry_interval", sizeof("retry_interval"), (void**)&z_retry_interval_pp)) {
247+
zval **z_retry_interval_pp;
248+
if (FAILURE != zend_hash_find(hOpts, "retry_interval", sizeof("retry_interval"), (void**)&z_retry_interval_pp)) {
244249
if (Z_TYPE_PP(z_retry_interval_pp) == IS_LONG || Z_TYPE_PP(z_retry_interval_pp) == IS_STRING) {
245250
if (Z_TYPE_PP(z_retry_interval_pp) == IS_LONG) {
246251
l_retry_interval = Z_LVAL_PP(z_retry_interval_pp);
@@ -259,7 +264,7 @@ PHP_METHOD(RedisArray, __construct)
259264
break;
260265

261266
case IS_ARRAY:
262-
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_dist, hPrev, b_index, l_retry_interval TSRMLS_CC);
267+
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_dist, hPrev, b_index, l_retry_interval, b_pconnect TSRMLS_CC);
263268
break;
264269

265270
default:

redis_array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct RedisArray_ {
4141
zval *z_multi_exec; /* Redis instance to be used in multi-exec */
4242
zend_bool index; /* use per-node index */
4343
zend_bool auto_rehash; /* migrate keys on read operations */
44+
zend_bool pconnect; /* should we use pconnect */
4445
zval *z_fun; /* key extractor, callable */
4546
zval *z_dist; /* key distributor, callable */
4647
zval *z_pure_cmds; /* hash table */

redis_array_impl.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

265280
RedisArray *
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) {

redis_array_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
RedisArray *ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval TSRMLS_DC);
99
RedisArray *ra_load_array(const char *name TSRMLS_DC);
10-
RedisArray *ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, long retry_interval TSRMLS_DC);
10+
RedisArray *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);
1111
zval *ra_find_node_by_name(RedisArray *ra, const char *host, int host_len TSRMLS_DC);
1212
zval *ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_DC);
1313
void ra_init_function_table(RedisArray *ra);

0 commit comments

Comments
 (0)