Skip to content

Commit 5bc6a4c

Browse files
author
Emmanuel Merali
committed
Added retrieval of specific instance form Array
Added the possibility to retrieve a specific Redis instance from the array. For instance: $r = $ra->_specified($ra->_target($key));
1 parent 78f0abf commit 5bc6a4c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

redis_array.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ zend_function_entry redis_array_functions[] = {
4545

4646
PHP_ME(RedisArray, _hosts, NULL, ZEND_ACC_PUBLIC)
4747
PHP_ME(RedisArray, _target, NULL, ZEND_ACC_PUBLIC)
48+
PHP_ME(RedisArray, _specified, NULL, ZEND_ACC_PUBLIC)
4849
PHP_ME(RedisArray, _function, NULL, ZEND_ACC_PUBLIC)
4950
PHP_ME(RedisArray, _distributor, NULL, ZEND_ACC_PUBLIC)
5051
PHP_ME(RedisArray, _rehash, NULL, ZEND_ACC_PUBLIC)
@@ -419,6 +420,31 @@ PHP_METHOD(RedisArray, _target)
419420
}
420421
}
421422

423+
PHP_METHOD(RedisArray, _specified)
424+
{
425+
zval *object;
426+
RedisArray *ra;
427+
char *target;
428+
int target_len;
429+
zval *z_redis;
430+
431+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
432+
&object, redis_array_ce, &target, &target_len) == FAILURE) {
433+
RETURN_FALSE;
434+
}
435+
436+
if (redis_array_get(object, &ra TSRMLS_CC) < 0) {
437+
RETURN_FALSE;
438+
}
439+
440+
z_redis = ra_find_node_by_name(ra, target, target_len TSRMLS_CC);
441+
if(z_redis) {
442+
RETURN_ZVAL(z_redis, 1, 0);
443+
} else {
444+
RETURN_NULL();
445+
}
446+
}
447+
422448
PHP_METHOD(RedisArray, _function)
423449
{
424450
zval *object;

redis_array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PHP_METHOD(RedisArray, __construct);
1010
PHP_METHOD(RedisArray, __call);
1111
PHP_METHOD(RedisArray, _hosts);
1212
PHP_METHOD(RedisArray, _target);
13+
PHP_METHOD(RedisArray, _specified);
1314
PHP_METHOD(RedisArray, _function);
1415
PHP_METHOD(RedisArray, _distributor);
1516
PHP_METHOD(RedisArray, _rehash);

0 commit comments

Comments
 (0)