Skip to content

Commit ae25be2

Browse files
authored
Merge pull request phpredis#1465 from yatsukhnenko/develop
Directly use return_value in RedisCluster::keys method
2 parents 6e455e2 + ad10a49 commit ae25be2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

redis_cluster.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ PHP_METHOD(RedisCluster, keys) {
10841084
strlen_t pat_len;
10851085
char *pat, *cmd;
10861086
clusterReply *resp;
1087-
zval zv, *z_ret = &zv;
10881087
int i, cmd_len;
10891088

10901089
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pat, &pat_len)
@@ -1096,19 +1095,20 @@ PHP_METHOD(RedisCluster, keys) {
10961095
/* Prefix and then build our command */
10971096
cmd_len = redis_spprintf(c->flags, NULL TSRMLS_CC, &cmd, "KEYS", "k", pat, pat_len);
10981097

1099-
array_init(z_ret);
1098+
array_init(return_value);
11001099

11011100
/* Treat as readonly */
11021101
c->readonly = CLUSTER_IS_ATOMIC(c);
11031102

11041103
/* Iterate over our known nodes */
11051104
ZEND_HASH_FOREACH_PTR(c->nodes, node) {
1106-
if (node == NULL) break;
1105+
if (node == NULL) continue;
11071106
if (cluster_send_slot(c, node->slot, cmd, cmd_len, TYPE_MULTIBULK
11081107
TSRMLS_CC) < 0)
11091108
{
11101109
php_error_docref(0 TSRMLS_CC, E_ERROR, "Can't send KEYS to %s:%d",
11111110
ZSTR_VAL(node->sock->host), node->sock->port);
1111+
zval_dtor(return_value);
11121112
efree(cmd);
11131113
RETURN_FALSE;
11141114
}
@@ -1129,7 +1129,7 @@ PHP_METHOD(RedisCluster, keys) {
11291129
continue;
11301130
}
11311131

1132-
add_next_index_stringl(z_ret, resp->element[i]->str,
1132+
add_next_index_stringl(return_value, resp->element[i]->str,
11331133
resp->element[i]->len);
11341134
}
11351135

@@ -1138,9 +1138,6 @@ PHP_METHOD(RedisCluster, keys) {
11381138
} ZEND_HASH_FOREACH_END();
11391139

11401140
efree(cmd);
1141-
1142-
/* Return our keys */
1143-
RETURN_ZVAL(z_ret, 1, 0);
11441141
}
11451142
/* }}} */
11461143

0 commit comments

Comments
 (0)