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

Skip to content

Commit ccd419a

Browse files
Small refactor of some methods
* Use our `redis_cmd_append_sstr_key_*` and `redis_cmd_append_sstr_zval` wrappers, which handle key prefixing and serialization transparently. * Rework ZADD so it can handle the bulk double response from the `INCR` options.
1 parent 71ce6dd commit ccd419a

14 files changed

Lines changed: 108 additions & 185 deletions

cluster_library.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,18 @@ cluster_zdiff_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) {
18191819
}
18201820
}
18211821

1822+
PHP_REDIS_API void
1823+
cluster_zadd_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) {
1824+
ZEND_ASSERT(ctx == NULL || ctx == PHPREDIS_CTX_PTR);
1825+
1826+
if (ctx == NULL) {
1827+
cluster_long_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1828+
} else {
1829+
cluster_dbl_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1830+
}
1831+
}
1832+
1833+
18221834
PHP_REDIS_API void
18231835
cluster_zrandmember_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx) {
18241836
if (ctx == NULL) {

cluster_library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ PHP_REDIS_API void cluster_hrandfield_resp(INTERNAL_FUNCTION_PARAMETERS, redisCl
418418
void *ctx);
419419
PHP_REDIS_API void cluster_zdiff_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
420420
void *ctx);
421+
PHP_REDIS_API void cluster_zadd_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
422+
void *ctx);
421423
PHP_REDIS_API void cluster_zrandmember_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
422424
void *ctx);
423425
PHP_REDIS_API void cluster_srandmember_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,

library.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,18 @@ redis_parse_client_list_response(char *response, zval *z_ret)
14261426
}
14271427
}
14281428

1429+
PHP_REDIS_API int
1430+
redis_zadd_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
1431+
{
1432+
FailableResultCallback cb;
1433+
1434+
ZEND_ASSERT(ctx == NULL || ctx == PHPREDIS_CTX_PTR);
1435+
1436+
cb = ctx ? redis_bulk_double_response : redis_long_response;
1437+
1438+
return cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, NULL);
1439+
}
1440+
14291441
PHP_REDIS_API int
14301442
redis_zrandmember_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
14311443
{

library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ PHP_REDIS_API int redis_read_raw_variant_reply(INTERNAL_FUNCTION_PARAMETERS, Red
183183
PHP_REDIS_API int redis_read_variant_reply_strings(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);
184184
PHP_REDIS_API int redis_client_list_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);
185185

186+
PHP_REDIS_API int redis_zadd_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);
186187
PHP_REDIS_API int redis_zrandmember_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);
187188
PHP_REDIS_API int redis_zdiff_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);
188189
PHP_REDIS_API int redis_set_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx);

redis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,7 @@ PHP_METHOD(Redis, brpoplpush) {
15831583

15841584
/* {{{ proto long Redis::zAdd(string key, int score, string value) */
15851585
PHP_METHOD(Redis, zAdd) {
1586-
REDIS_PROCESS_CMD(zadd, redis_long_response);
1586+
REDIS_PROCESS_CMD(zadd, redis_zadd_response);
15871587
}
15881588
/* }}} */
15891589

redis.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ public function flushDB(?bool $sync = null): Redis|bool;
12141214

12151215
/**
12161216
* Functions is an API for managing code to be executed on the server.
1217-
*
1217+
*
12181218
* @param string $operation The subcommand you intend to execute. Valid options are as follows
12191219
* 'LOAD' - Create a new library with the given library name and code.
12201220
* 'DELETE' - Delete the given library.
@@ -4004,7 +4004,7 @@ public function xtrim(string $key, string $threshold, bool $approx = false, bool
40044004
* @example $redis->zadd('zs', 1, 'first', 2, 'second', 3, 'third');
40054005
* @example $redis->zAdd('zs', ['XX'], 8, 'second', 99, 'new-element');
40064006
*/
4007-
public function zAdd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems): Redis|int|false;
4007+
public function zAdd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems): Redis|int|float|false;
40084008

40094009
/**
40104010
* Return the number of elements in a sorted set.

redis_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 600a10da9438d33050be825dff3683399737cc5e */
2+
* Stub hash: 8cf0ecc2f5a43c6ede68d537a76faa23cb912d96 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null")
@@ -1000,7 +1000,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_xtrim, 0, 2, Red
10001000
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limit, IS_LONG, 0, "-1")
10011001
ZEND_END_ARG_INFO()
10021002

1003-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_zAdd, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE)
1003+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_zAdd, 0, 2, Redis, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_FALSE)
10041004
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
10051005
ZEND_ARG_TYPE_MASK(0, score_or_options, MAY_BE_ARRAY|MAY_BE_DOUBLE, NULL)
10061006
ZEND_ARG_VARIADIC_TYPE_INFO(0, more_scores_and_mems, IS_MIXED, 0)

redis_cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ PHP_METHOD(RedisCluster, zmscore) {
10841084

10851085
/* {{{ proto long RedisCluster::zadd(string key,double score,string mem, ...) */
10861086
PHP_METHOD(RedisCluster, zadd) {
1087-
CLUSTER_PROCESS_CMD(zadd, cluster_long_resp, 0);
1087+
CLUSTER_PROCESS_CMD(zadd, cluster_zadd_resp, 0);
10881088
}
10891089
/* }}} */
10901090

redis_cluster.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ public function xtrim(string $key, int $maxlen, bool $approx = false, bool $mini
10351035
/**
10361036
* @see Redis::zadd
10371037
*/
1038-
public function zadd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems): RedisCluster|int|false;
1038+
public function zadd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems): RedisCluster|int|float|false;
10391039

10401040
/**
10411041
* @see Redis::zcard

redis_cluster_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: eabecbc2e536faca2a9fcba3c99ad0aeba9721b4 */
2+
* Stub hash: 32b24ce215ff4f2299dd838fab7cbc36b81b65eb */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -891,7 +891,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_xtrim, 0,
891891
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, limit, IS_LONG, 0, "-1")
892892
ZEND_END_ARG_INFO()
893893

894-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_zadd, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE)
894+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_zadd, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_FALSE)
895895
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
896896
ZEND_ARG_TYPE_MASK(0, score_or_options, MAY_BE_ARRAY|MAY_BE_DOUBLE, NULL)
897897
ZEND_ARG_VARIADIC_TYPE_INFO(0, more_scores_and_mems, IS_MIXED, 0)

0 commit comments

Comments
 (0)