mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Added bool index parameter to RedisArray constructor
This commit is contained in:
+7
-6
@@ -169,7 +169,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts)
|
||||
}
|
||||
|
||||
RedisArray *
|
||||
ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev) {
|
||||
ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev, zend_bool b_index) {
|
||||
|
||||
int count = zend_hash_num_elements(hosts);
|
||||
|
||||
@@ -179,7 +179,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev) {
|
||||
ra->redis = emalloc(count * sizeof(zval*));
|
||||
ra->count = count;
|
||||
ra->z_fun = NULL;
|
||||
ra->index = 1;
|
||||
ra->index = b_index;
|
||||
|
||||
/* init array data structures */
|
||||
redis_array_init(ra);
|
||||
@@ -187,7 +187,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev) {
|
||||
if(NULL == ra_load_hosts(ra, hosts)) {
|
||||
return NULL;
|
||||
}
|
||||
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, NULL) : NULL;
|
||||
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, NULL, b_index) : NULL;
|
||||
|
||||
/* copy function if provided */
|
||||
if(z_fun) {
|
||||
@@ -337,8 +337,9 @@ PHP_METHOD(RedisArray, __construct)
|
||||
char *name = NULL;
|
||||
int id;
|
||||
RedisArray *ra = NULL;
|
||||
zend_bool b_index = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|za", &z0, &z_fun, &z_prev) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|zab", &z0, &z_fun, &z_prev, &b_index) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
@@ -349,7 +350,7 @@ PHP_METHOD(RedisArray, __construct)
|
||||
break;
|
||||
|
||||
case IS_ARRAY:
|
||||
ra = ra_make_array(Z_ARRVAL_P(z0), NULL, z_prev ? Z_ARRVAL_P(z_prev):NULL);
|
||||
ra = ra_make_array(Z_ARRVAL_P(z0), NULL, z_prev ? Z_ARRVAL_P(z_prev):NULL, b_index);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -361,7 +362,7 @@ PHP_METHOD(RedisArray, __construct)
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
// printf("ARRAY OF HOSTS, fun=%s\n", fun);
|
||||
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_prev ? Z_ARRVAL_P(z_prev):NULL);
|
||||
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_prev ? Z_ARRVAL_P(z_prev):NULL, b_index);
|
||||
}
|
||||
|
||||
if(ra) {
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ typedef struct RedisArray_ {
|
||||
uint32_t crc32(const char *s, size_t sz);
|
||||
|
||||
void redis_array_init(RedisArray *ra);
|
||||
RedisArray *ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev);
|
||||
RedisArray *ra_make_array(HashTable *hosts, zval *z_fun, HashTable *hosts_prev, zend_bool b_index);
|
||||
zval *ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// can't set anything that hasn't been declared when the extension loads.
|
||||
ini_set('redis.array.names', 'users,friends');
|
||||
ini_set('redis.array.hosts', 'users=localhost:6379,localhost:6380,localhost:6381,localhost:6382');
|
||||
ini_set('redis.array.index', 'users=1,friends=0');
|
||||
|
||||
// var_dump(ini_get('redis.arrays.names'));
|
||||
// var_dump(ini_get('redis.arrays.hosts'));
|
||||
@@ -17,7 +18,7 @@ $ra = new RedisArray(array('localhost'));
|
||||
var_dump($ra->set('hello', 'world'));
|
||||
var_dump($ra->get('hello'));
|
||||
|
||||
$ra = new RedisArray(array('localhost:6380', 'localhost:6381', 'localhost:6382'), NULL, array('localhost')); // after resizing
|
||||
$ra = new RedisArray(array('localhost:6380', 'localhost:6381', 'localhost:6382'), NULL, array('localhost'), TRUE); // after resizing
|
||||
var_dump($ra->get('hello'));
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user