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

Skip to content

Commit e222b85

Browse files
Implement HRANDFIELD for RedisCluster
See #1894
1 parent fa5d1af commit e222b85

7 files changed

Lines changed: 45 additions & 8 deletions

cluster_library.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,20 @@ PHP_REDIS_API void cluster_ping_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
17471747
CLUSTER_RETURN_BOOL(c, 1);
17481748
}
17491749

1750+
PHP_REDIS_API void
1751+
cluster_hrandfield_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx)
1752+
{
1753+
if (ctx == NULL) {
1754+
cluster_bulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1755+
} else if (ctx == PHPREDIS_CTX_PTR) {
1756+
cluster_mbulk_raw_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1757+
} else if (ctx == PHPREDIS_CTX_PTR + 1) {
1758+
return cluster_mbulk_zipdbl_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
1759+
} else {
1760+
ZEND_ASSERT(!"memory corruption?");
1761+
}
1762+
}
1763+
17501764
PHP_REDIS_API void
17511765
cluster_pop_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, void *ctx)
17521766
{

cluster_library.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ PHP_REDIS_API void cluster_pop_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
412412
void *ctx);
413413
PHP_REDIS_API void cluster_lpos_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
414414
void *ctx);
415+
PHP_REDIS_API void cluster_hrandfield_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
416+
void *ctx);
415417
PHP_REDIS_API void cluster_set_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
416418
void *ctx);
417419
PHP_REDIS_API void cluster_geosearch_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,

redis_cluster.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,12 @@ PHP_METHOD(RedisCluster, hmset) {
12121212
}
12131213
/* }}} */
12141214

1215+
/* {{{ proto bool RedisCluster::hrandfield(string key, [array $options]) */
1216+
PHP_METHOD(RedisCluster, hrandfield) {
1217+
CLUSTER_PROCESS_CMD(hrandfield, cluster_hrandfield_resp, 1);
1218+
}
1219+
/* }}} */
1220+
12151221
/* {{{ proto long RedisCluster::hdel(string key, string mem1, ... memN) */
12161222
PHP_METHOD(RedisCluster, hdel) {
12171223
CLUSTER_PROCESS_CMD(hdel, cluster_long_resp, 0);

redis_cluster.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ public function hmset(string $key, array $key_values): RedisCluster|bool;
482482
*/
483483
public function hscan(string $key, ?int &$iterator, ?string $pattern = null, int $count = 0): array|bool;
484484

485+
/**
486+
* @see https://redis.io/commands/hrandfield
487+
*/
488+
public function hrandfield(string $key, array $options = null): RedisCluster|string|array;
489+
485490
/**
486491
* @see Redis::hset
487492
*/

redis_cluster_arginfo.h

Lines changed: 8 additions & 1 deletion
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: ed8ae1edcec62f211d6ba70e78b3c0f087b2cbde */
2+
* Stub hash: 2225d10403eb94c52ad017310e783115b9ea869e */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -398,6 +398,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster_hscan, 0, 2,
398398
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
399399
ZEND_END_ARG_INFO()
400400

401+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_hrandfield, 0, 1, RedisCluster, MAY_BE_STRING|MAY_BE_ARRAY)
402+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
403+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null")
404+
ZEND_END_ARG_INFO()
405+
401406
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_hset, 0, 3, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE)
402407
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
403408
ZEND_ARG_TYPE_INFO(0, member, IS_STRING, 0)
@@ -1088,6 +1093,7 @@ ZEND_METHOD(RedisCluster, hlen);
10881093
ZEND_METHOD(RedisCluster, hmget);
10891094
ZEND_METHOD(RedisCluster, hmset);
10901095
ZEND_METHOD(RedisCluster, hscan);
1096+
ZEND_METHOD(RedisCluster, hrandfield);
10911097
ZEND_METHOD(RedisCluster, hset);
10921098
ZEND_METHOD(RedisCluster, hsetnx);
10931099
ZEND_METHOD(RedisCluster, hstrlen);
@@ -1305,6 +1311,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
13051311
ZEND_ME(RedisCluster, hmget, arginfo_class_RedisCluster_hmget, ZEND_ACC_PUBLIC)
13061312
ZEND_ME(RedisCluster, hmset, arginfo_class_RedisCluster_hmset, ZEND_ACC_PUBLIC)
13071313
ZEND_ME(RedisCluster, hscan, arginfo_class_RedisCluster_hscan, ZEND_ACC_PUBLIC)
1314+
ZEND_ME(RedisCluster, hrandfield, arginfo_class_RedisCluster_hrandfield, ZEND_ACC_PUBLIC)
13081315
ZEND_ME(RedisCluster, hset, arginfo_class_RedisCluster_hset, ZEND_ACC_PUBLIC)
13091316
ZEND_ME(RedisCluster, hsetnx, arginfo_class_RedisCluster_hsetnx, ZEND_ACC_PUBLIC)
13101317
ZEND_ME(RedisCluster, hstrlen, arginfo_class_RedisCluster_hstrlen, ZEND_ACC_PUBLIC)

redis_cluster_legacy_arginfo.h

Lines changed: 10 additions & 6 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: ed8ae1edcec62f211d6ba70e78b3c0f087b2cbde */
2+
* Stub hash: 2225d10403eb94c52ad017310e783115b9ea869e */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)
@@ -350,6 +350,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_hscan, 0, 0, 2)
350350
ZEND_ARG_INFO(0, count)
351351
ZEND_END_ARG_INFO()
352352

353+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_hrandfield, 0, 0, 1)
354+
ZEND_ARG_INFO(0, key)
355+
ZEND_ARG_INFO(0, options)
356+
ZEND_END_ARG_INFO()
357+
353358
#define arginfo_class_RedisCluster_hset arginfo_class_RedisCluster_hincrby
354359

355360
#define arginfo_class_RedisCluster_hsetnx arginfo_class_RedisCluster_hincrby
@@ -618,12 +623,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_smove, 0, 0, 3)
618623
ZEND_ARG_INFO(0, member)
619624
ZEND_END_ARG_INFO()
620625

621-
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_sort, 0, 0, 1)
622-
ZEND_ARG_INFO(0, key)
623-
ZEND_ARG_INFO(0, options)
624-
ZEND_END_ARG_INFO()
626+
#define arginfo_class_RedisCluster_sort arginfo_class_RedisCluster_hrandfield
625627

626-
#define arginfo_class_RedisCluster_sort_ro arginfo_class_RedisCluster_sort
628+
#define arginfo_class_RedisCluster_sort_ro arginfo_class_RedisCluster_hrandfield
627629

628630
#define arginfo_class_RedisCluster_spop arginfo_class_RedisCluster_lpop
629631

@@ -935,6 +937,7 @@ ZEND_METHOD(RedisCluster, hlen);
935937
ZEND_METHOD(RedisCluster, hmget);
936938
ZEND_METHOD(RedisCluster, hmset);
937939
ZEND_METHOD(RedisCluster, hscan);
940+
ZEND_METHOD(RedisCluster, hrandfield);
938941
ZEND_METHOD(RedisCluster, hset);
939942
ZEND_METHOD(RedisCluster, hsetnx);
940943
ZEND_METHOD(RedisCluster, hstrlen);
@@ -1152,6 +1155,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
11521155
ZEND_ME(RedisCluster, hmget, arginfo_class_RedisCluster_hmget, ZEND_ACC_PUBLIC)
11531156
ZEND_ME(RedisCluster, hmset, arginfo_class_RedisCluster_hmset, ZEND_ACC_PUBLIC)
11541157
ZEND_ME(RedisCluster, hscan, arginfo_class_RedisCluster_hscan, ZEND_ACC_PUBLIC)
1158+
ZEND_ME(RedisCluster, hrandfield, arginfo_class_RedisCluster_hrandfield, ZEND_ACC_PUBLIC)
11551159
ZEND_ME(RedisCluster, hset, arginfo_class_RedisCluster_hset, ZEND_ACC_PUBLIC)
11561160
ZEND_ME(RedisCluster, hsetnx, arginfo_class_RedisCluster_hsetnx, ZEND_ACC_PUBLIC)
11571161
ZEND_ME(RedisCluster, hstrlen, arginfo_class_RedisCluster_hstrlen, ZEND_ACC_PUBLIC)

tests/RedisClusterTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function testzDiffStore() { return $this->markTestSkipped(); }
5858
public function testzMscore() { return $this->marktestSkipped(); }
5959
public function testZRandMember() { return $this->marktestSkipped(); }
6060
public function testCopy() { return $this->marktestSkipped(); }
61-
public function testHRandField() { return $this->marktestSkipped(); }
6261
public function testConfig() { return $this->markTestSkipped(); }
6362
public function testFlushDB() { return $this->markTestSkipped(); }
6463

0 commit comments

Comments
 (0)