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

Skip to content

Commit dcbeae7

Browse files
Persistent connections with RedisArray
Re-integrating the now old ra-performance branch into a git-flow branch. I could have merged it but this was easier with so few changes
1 parent 2099f19 commit dcbeae7

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
160160
zval *z_params_index;
161161
zval *z_params_autorehash;
162162
zval *z_params_retry_interval;
163+
zval *z_params_pconnect;
163164
RedisArray *ra = NULL;
164165

165-
zend_bool b_index = 0, b_autorehash = 0;
166+
zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
166167
long l_retry_interval = 0;
167168
HashTable *hHosts = NULL, *hPrev = NULL;
168169

@@ -241,8 +242,18 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
241242
}
242243
}
243244

245+
/* find pconnect option */
246+
MAKE_STD_ZVAL(z_params_pconnect);
247+
array_init(z_params_pconnect);
248+
sapi_module.treat_data(PARSE_STRING, estrdup(INI_STR("redis.arrays.pconnect")), z_params_pconnect TSRMLS_CC);
249+
if (zend_hash_find(Z_ARRVAL_P(z_params_pconnect), name, strlen(name) + 1, (void**) &z_data_pp) != FAILURE) {
250+
if(Z_TYPE_PP(z_data_pp) == IS_STRING && strncmp(Z_STRVAL_PP(z_data_pp), "1", 1) == 0) {
251+
b_pconnect = 1;
252+
}
253+
}
254+
244255
/* create RedisArray object */
245-
ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index, l_retry_interval TSRMLS_CC);
256+
ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index, l_retry_interval, b_pconnect TSRMLS_CC);
246257
ra->auto_rehash = b_autorehash;
247258

248259
/* cleanup */
@@ -258,12 +269,14 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
258269
efree(z_params_autorehash);
259270
zval_dtor(z_params_retry_interval);
260271
efree(z_params_retry_interval);
272+
zval_dtor(z_params_pconnect);
273+
efree(z_params_pconnect);
261274

262275
return ra;
263276
}
264277

265278
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) {
279+
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) {
267280

268281
int count = zend_hash_num_elements(hosts);
269282

@@ -284,7 +297,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
284297
if(NULL == ra_load_hosts(ra, hosts, retry_interval TSRMLS_CC)) {
285298
return NULL;
286299
}
287-
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, retry_interval TSRMLS_CC) : NULL;
300+
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, retry_interval, b_pconnect TSRMLS_CC) : NULL;
288301

289302
/* copy function if provided */
290303
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)