Skip to content

Commit 6ce3bd5

Browse files
Implement VRANGE command and add a test
1 parent 7a69d73 commit 6ce3bd5

11 files changed

+121
-11
lines changed

redis.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,6 +3209,10 @@ PHP_METHOD(Redis, vrandmember) {
32093209
redis_randmember_response);
32103210
}
32113211

3212+
PHP_METHOD(Redis, vrange) {
3213+
REDIS_PROCESS_KW_CMD("VRANGE", redis_vrange_cmd, redis_sock_read_multibulk_reply);
3214+
}
3215+
32123216
PHP_METHOD(Redis, vrem) {
32133217
REDIS_PROCESS_KW_CMD("VREM", redis_kv_cmd, redis_long_response);
32143218
}

redis.stub.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,6 +4299,18 @@ public function vemb(string $key, mixed $member, bool $raw = false): Redis|array
42994299
*/
43004300
public function vrandmember(string $key, int $count = 0): Redis|array|string|false;
43014301

4302+
/**
4303+
* Retreive a lexographical range of elements from a vector set
4304+
*
4305+
* @param string $key The vector set to query.
4306+
* @param string $min The minimum element to return.
4307+
* @param string $max The maximum element to return.
4308+
* @param int $count An optional maximum number of elements to return.
4309+
*
4310+
* @return Redis|array|false An array of elements in the requested range or false on failure.
4311+
*/
4312+
public function vrange(string $key, string $min, string $max, int $count = -1): Redis|array|false;
4313+
43024314
/**
43034315
* Remove an element from a vector set
43044316
*
@@ -4329,8 +4341,6 @@ public function vsetattr(string $key, mixed $member, array|string $attributes):
43294341
* @param mixed $member The member to query.
43304342
* @param bool $decode Whether to automatically deserialize any returned json.
43314343
*
4332-
*
4333-
*
43344344
* @return Redis|array|false An array of attributes for the member or false on failure.
43354345
*/
43364346
public function vgetattr(string $key, mixed $member, bool $decode = true): Redis|array|string|false;

redis_arginfo.h

Lines changed: 10 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: 26d337d9f4984fe9e2c15c4245620494cb6ac24e */
2+
* Stub hash: 619374bbad94b8a9992f9c11abd12362e07359d0 */
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, 1, "null")
@@ -1098,6 +1098,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_vrandmember, 0,
10981098
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
10991099
ZEND_END_ARG_INFO()
11001100

1101+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_vrange, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
1102+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
1103+
ZEND_ARG_TYPE_INFO(0, min, IS_STRING, 0)
1104+
ZEND_ARG_TYPE_INFO(0, max, IS_STRING, 0)
1105+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
1106+
ZEND_END_ARG_INFO()
1107+
11011108
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_vrem, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE)
11021109
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
11031110
ZEND_ARG_TYPE_INFO(0, member, IS_MIXED, 0)
@@ -1537,6 +1544,7 @@ ZEND_METHOD(Redis, vinfo);
15371544
ZEND_METHOD(Redis, vismember);
15381545
ZEND_METHOD(Redis, vemb);
15391546
ZEND_METHOD(Redis, vrandmember);
1547+
ZEND_METHOD(Redis, vrange);
15401548
ZEND_METHOD(Redis, vrem);
15411549
ZEND_METHOD(Redis, vsetattr);
15421550
ZEND_METHOD(Redis, vgetattr);
@@ -1825,6 +1833,7 @@ static const zend_function_entry class_Redis_methods[] = {
18251833
ZEND_ME(Redis, vismember, arginfo_class_Redis_vismember, ZEND_ACC_PUBLIC)
18261834
ZEND_ME(Redis, vemb, arginfo_class_Redis_vemb, ZEND_ACC_PUBLIC)
18271835
ZEND_ME(Redis, vrandmember, arginfo_class_Redis_vrandmember, ZEND_ACC_PUBLIC)
1836+
ZEND_ME(Redis, vrange, arginfo_class_Redis_vrange, ZEND_ACC_PUBLIC)
18281837
ZEND_ME(Redis, vrem, arginfo_class_Redis_vrem, ZEND_ACC_PUBLIC)
18291838
ZEND_ME(Redis, vsetattr, arginfo_class_Redis_vsetattr, ZEND_ACC_PUBLIC)
18301839
ZEND_ME(Redis, vgetattr, arginfo_class_Redis_vgetattr, ZEND_ACC_PUBLIC)

redis_cluster.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,10 @@ PHP_METHOD(RedisCluster, vrandmember) {
32133213
cluster_randmember_resp, 1);
32143214
}
32153215

3216+
PHP_METHOD(RedisCluster, vrange) {
3217+
CLUSTER_PROCESS_KW_CMD("VRANGE", redis_vrange_cmd, cluster_mbulk_resp, 1);
3218+
}
3219+
32163220
PHP_METHOD(RedisCluster, vrem) {
32173221
CLUSTER_PROCESS_KW_CMD("VREM", redis_kv_cmd, cluster_long_resp, 0);
32183222
}

redis_cluster.stub.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,19 @@ public function vemb(string $key, mixed $member, bool $raw = false): RedisCluste
11081108
*/
11091109
public function vrandmember(string $key, int $count = 0): RedisCluster|array|string|false;
11101110

1111+
/**
1112+
* Retreive a lexographical range of elements from a vector set
1113+
*
1114+
* @param string $key The vector set to query.
1115+
* @param string $min The minimum element to return.
1116+
* @param string $max The maximum element to return.
1117+
* @param int $count An optional maximum number of elements to return.
1118+
*
1119+
* @return RedisCluster|array|false An array of elements in the specified range.`
1120+
*/
1121+
public function vrange(string $key, string $min, string $max, int $count = -1): RedisCluster|array|false;
1122+
1123+
11111124
/**
11121125
* @see Redis::vrem
11131126
*/

redis_cluster_arginfo.h

Lines changed: 10 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: c8d6113b07ba9386e41ab8513190c87415676bd0 */
2+
* Stub hash: d504e84c671162c4ec78aa1e6bb5a47c695ee90d */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -914,6 +914,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_vrandmemb
914914
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
915915
ZEND_END_ARG_INFO()
916916

917+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_vrange, 0, 3, RedisCluster, MAY_BE_ARRAY|MAY_BE_FALSE)
918+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
919+
ZEND_ARG_TYPE_INFO(0, min, IS_STRING, 0)
920+
ZEND_ARG_TYPE_INFO(0, max, IS_STRING, 0)
921+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
922+
ZEND_END_ARG_INFO()
923+
917924
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_vrem, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE)
918925
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
919926
ZEND_ARG_TYPE_INFO(0, member, IS_MIXED, 0)
@@ -1377,6 +1384,7 @@ ZEND_METHOD(RedisCluster, vinfo);
13771384
ZEND_METHOD(RedisCluster, vismember);
13781385
ZEND_METHOD(RedisCluster, vemb);
13791386
ZEND_METHOD(RedisCluster, vrandmember);
1387+
ZEND_METHOD(RedisCluster, vrange);
13801388
ZEND_METHOD(RedisCluster, vrem);
13811389
ZEND_METHOD(RedisCluster, vlinks);
13821390
ZEND_METHOD(RedisCluster, vgetattr);
@@ -1633,6 +1641,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
16331641
ZEND_ME(RedisCluster, vismember, arginfo_class_RedisCluster_vismember, ZEND_ACC_PUBLIC)
16341642
ZEND_ME(RedisCluster, vemb, arginfo_class_RedisCluster_vemb, ZEND_ACC_PUBLIC)
16351643
ZEND_ME(RedisCluster, vrandmember, arginfo_class_RedisCluster_vrandmember, ZEND_ACC_PUBLIC)
1644+
ZEND_ME(RedisCluster, vrange, arginfo_class_RedisCluster_vrange, ZEND_ACC_PUBLIC)
16361645
ZEND_ME(RedisCluster, vrem, arginfo_class_RedisCluster_vrem, ZEND_ACC_PUBLIC)
16371646
ZEND_ME(RedisCluster, vlinks, arginfo_class_RedisCluster_vlinks, ZEND_ACC_PUBLIC)
16381647
ZEND_ME(RedisCluster, vgetattr, arginfo_class_RedisCluster_vgetattr, ZEND_ACC_PUBLIC)

redis_cluster_legacy_arginfo.h

Lines changed: 10 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: c8d6113b07ba9386e41ab8513190c87415676bd0 */
2+
* Stub hash: d504e84c671162c4ec78aa1e6bb5a47c695ee90d */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)
@@ -771,6 +771,13 @@ ZEND_END_ARG_INFO()
771771

772772
#define arginfo_class_RedisCluster_vrandmember arginfo_class_RedisCluster_lpop
773773

774+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_vrange, 0, 0, 3)
775+
ZEND_ARG_INFO(0, key)
776+
ZEND_ARG_INFO(0, min)
777+
ZEND_ARG_INFO(0, max)
778+
ZEND_ARG_INFO(0, count)
779+
ZEND_END_ARG_INFO()
780+
774781
#define arginfo_class_RedisCluster_vrem arginfo_class_RedisCluster_hexists
775782

776783
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_vlinks, 0, 0, 2)
@@ -1206,6 +1213,7 @@ ZEND_METHOD(RedisCluster, vinfo);
12061213
ZEND_METHOD(RedisCluster, vismember);
12071214
ZEND_METHOD(RedisCluster, vemb);
12081215
ZEND_METHOD(RedisCluster, vrandmember);
1216+
ZEND_METHOD(RedisCluster, vrange);
12091217
ZEND_METHOD(RedisCluster, vrem);
12101218
ZEND_METHOD(RedisCluster, vlinks);
12111219
ZEND_METHOD(RedisCluster, vgetattr);
@@ -1462,6 +1470,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
14621470
ZEND_ME(RedisCluster, vismember, arginfo_class_RedisCluster_vismember, ZEND_ACC_PUBLIC)
14631471
ZEND_ME(RedisCluster, vemb, arginfo_class_RedisCluster_vemb, ZEND_ACC_PUBLIC)
14641472
ZEND_ME(RedisCluster, vrandmember, arginfo_class_RedisCluster_vrandmember, ZEND_ACC_PUBLIC)
1473+
ZEND_ME(RedisCluster, vrange, arginfo_class_RedisCluster_vrange, ZEND_ACC_PUBLIC)
14651474
ZEND_ME(RedisCluster, vrem, arginfo_class_RedisCluster_vrem, ZEND_ACC_PUBLIC)
14661475
ZEND_ME(RedisCluster, vlinks, arginfo_class_RedisCluster_vlinks, ZEND_ACC_PUBLIC)
14671476
ZEND_ME(RedisCluster, vgetattr, arginfo_class_RedisCluster_vgetattr, ZEND_ACC_PUBLIC)

redis_commands.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5856,14 +5856,16 @@ int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
58565856
}
58575857

58585858
/* X[REV]RANGE key start end [COUNT count] */
5859-
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
5860-
char *kw, char **cmd, int *cmd_len, short *slot,
5861-
void **ctx)
5859+
static int
5860+
redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
5861+
char *kw, zend_bool have_count_literal, char **cmd,
5862+
int *cmd_len, short *slot, void **ctx)
58625863
{
58635864
smart_string cmdstr = {0};
58645865
char *key, *start, *end;
58655866
size_t keylen, startlen, endlen;
58665867
zend_long count = -1;
5868+
int argc;
58675869

58685870
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &key, &keylen,
58695871
&start, &startlen, &end, &endlen, &count)
@@ -5872,13 +5874,16 @@ int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
58725874
return FAILURE;
58735875
}
58745876

5875-
redis_cmd_init_sstr(&cmdstr, 3 + (2 * (count > -1)), kw, strlen(kw));
5877+
argc = 3 + ((have_count_literal ? 2 : 1) * (count > -1));
5878+
redis_cmd_init_sstr(&cmdstr, argc, kw, strlen(kw));
5879+
58765880
redis_cmd_append_sstr_key(&cmdstr, key, keylen, redis_sock, slot);
58775881
redis_cmd_append_sstr(&cmdstr, start, startlen);
58785882
redis_cmd_append_sstr(&cmdstr, end, endlen);
58795883

58805884
if (count > -1) {
5881-
redis_cmd_append_sstr(&cmdstr, ZEND_STRL("COUNT"));
5885+
if (have_count_literal)
5886+
redis_cmd_append_sstr(&cmdstr, ZEND_STRL("COUNT"));
58825887
redis_cmd_append_sstr_long(&cmdstr, count);
58835888
}
58845889

@@ -5887,6 +5892,22 @@ int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
58875892
return SUCCESS;
58885893
}
58895894

5895+
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
5896+
char *kw, char **cmd, int *cmd_len, short *slot,
5897+
void **ctx)
5898+
{
5899+
return redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
5900+
redis_sock, kw, 1, cmd, cmd_len, slot, ctx);
5901+
}
5902+
5903+
int redis_vrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
5904+
char *kw, char **cmd, int *cmd_len, short *slot,
5905+
void **ctx)
5906+
{
5907+
return redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
5908+
redis_sock, kw, 0, cmd, cmd_len, slot, ctx);
5909+
}
5910+
58905911
/* Helper function to take an associative array and append the Redis
58915912
* STREAMS stream [stream...] id [id ...] arguments to a command string. */
58925913
static int

redis_commands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
191191
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
192192
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
193193

194+
int redis_vrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
195+
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
196+
194197
int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
195198
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
196199

redis_legacy_arginfo.h

Lines changed: 10 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: 26d337d9f4984fe9e2c15c4245620494cb6ac24e */
2+
* Stub hash: 619374bbad94b8a9992f9c11abd12362e07359d0 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -972,6 +972,13 @@ ZEND_END_ARG_INFO()
972972

973973
#define arginfo_class_Redis_vrandmember arginfo_class_Redis_lPop
974974

975+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_vrange, 0, 0, 3)
976+
ZEND_ARG_INFO(0, key)
977+
ZEND_ARG_INFO(0, min)
978+
ZEND_ARG_INFO(0, max)
979+
ZEND_ARG_INFO(0, count)
980+
ZEND_END_ARG_INFO()
981+
975982
#define arginfo_class_Redis_vrem arginfo_class_Redis_hGet
976983

977984
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_vsetattr, 0, 0, 3)
@@ -1369,6 +1376,7 @@ ZEND_METHOD(Redis, vinfo);
13691376
ZEND_METHOD(Redis, vismember);
13701377
ZEND_METHOD(Redis, vemb);
13711378
ZEND_METHOD(Redis, vrandmember);
1379+
ZEND_METHOD(Redis, vrange);
13721380
ZEND_METHOD(Redis, vrem);
13731381
ZEND_METHOD(Redis, vsetattr);
13741382
ZEND_METHOD(Redis, vgetattr);
@@ -1657,6 +1665,7 @@ static const zend_function_entry class_Redis_methods[] = {
16571665
ZEND_ME(Redis, vismember, arginfo_class_Redis_vismember, ZEND_ACC_PUBLIC)
16581666
ZEND_ME(Redis, vemb, arginfo_class_Redis_vemb, ZEND_ACC_PUBLIC)
16591667
ZEND_ME(Redis, vrandmember, arginfo_class_Redis_vrandmember, ZEND_ACC_PUBLIC)
1668+
ZEND_ME(Redis, vrange, arginfo_class_Redis_vrange, ZEND_ACC_PUBLIC)
16601669
ZEND_ME(Redis, vrem, arginfo_class_Redis_vrem, ZEND_ACC_PUBLIC)
16611670
ZEND_ME(Redis, vsetattr, arginfo_class_Redis_vsetattr, ZEND_ACC_PUBLIC)
16621671
ZEND_ME(Redis, vgetattr, arginfo_class_Redis_vgetattr, ZEND_ACC_PUBLIC)

0 commit comments

Comments
 (0)