mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Implement VRANGE command and add a test
This commit is contained in:
committed by
Michael Grunder
parent
7a69d7301c
commit
6ce3bd533a
@@ -3209,6 +3209,10 @@ PHP_METHOD(Redis, vrandmember) {
|
||||
redis_randmember_response);
|
||||
}
|
||||
|
||||
PHP_METHOD(Redis, vrange) {
|
||||
REDIS_PROCESS_KW_CMD("VRANGE", redis_vrange_cmd, redis_sock_read_multibulk_reply);
|
||||
}
|
||||
|
||||
PHP_METHOD(Redis, vrem) {
|
||||
REDIS_PROCESS_KW_CMD("VREM", redis_kv_cmd, redis_long_response);
|
||||
}
|
||||
|
||||
+12
-2
@@ -4299,6 +4299,18 @@ class Redis {
|
||||
*/
|
||||
public function vrandmember(string $key, int $count = 0): Redis|array|string|false;
|
||||
|
||||
/**
|
||||
* Retreive a lexographical range of elements from a vector set
|
||||
*
|
||||
* @param string $key The vector set to query.
|
||||
* @param string $min The minimum element to return.
|
||||
* @param string $max The maximum element to return.
|
||||
* @param int $count An optional maximum number of elements to return.
|
||||
*
|
||||
* @return Redis|array|false An array of elements in the requested range or false on failure.
|
||||
*/
|
||||
public function vrange(string $key, string $min, string $max, int $count = -1): Redis|array|false;
|
||||
|
||||
/**
|
||||
* Remove an element from a vector set
|
||||
*
|
||||
@@ -4329,8 +4341,6 @@ class Redis {
|
||||
* @param mixed $member The member to query.
|
||||
* @param bool $decode Whether to automatically deserialize any returned json.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @return Redis|array|false An array of attributes for the member or false on failure.
|
||||
*/
|
||||
public function vgetattr(string $key, mixed $member, bool $decode = true): Redis|array|string|false;
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 26d337d9f4984fe9e2c15c4245620494cb6ac24e */
|
||||
* Stub hash: 619374bbad94b8a9992f9c11abd12362e07359d0 */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
|
||||
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,
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_vrange, 0, 3, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, min, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, max, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_vrem, 0, 2, Redis, MAY_BE_LONG|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, member, IS_MIXED, 0)
|
||||
@@ -1537,6 +1544,7 @@ ZEND_METHOD(Redis, vinfo);
|
||||
ZEND_METHOD(Redis, vismember);
|
||||
ZEND_METHOD(Redis, vemb);
|
||||
ZEND_METHOD(Redis, vrandmember);
|
||||
ZEND_METHOD(Redis, vrange);
|
||||
ZEND_METHOD(Redis, vrem);
|
||||
ZEND_METHOD(Redis, vsetattr);
|
||||
ZEND_METHOD(Redis, vgetattr);
|
||||
@@ -1825,6 +1833,7 @@ static const zend_function_entry class_Redis_methods[] = {
|
||||
ZEND_ME(Redis, vismember, arginfo_class_Redis_vismember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vemb, arginfo_class_Redis_vemb, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrandmember, arginfo_class_Redis_vrandmember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrange, arginfo_class_Redis_vrange, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrem, arginfo_class_Redis_vrem, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vsetattr, arginfo_class_Redis_vsetattr, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vgetattr, arginfo_class_Redis_vgetattr, ZEND_ACC_PUBLIC)
|
||||
|
||||
@@ -3213,6 +3213,10 @@ PHP_METHOD(RedisCluster, vrandmember) {
|
||||
cluster_randmember_resp, 1);
|
||||
}
|
||||
|
||||
PHP_METHOD(RedisCluster, vrange) {
|
||||
CLUSTER_PROCESS_KW_CMD("VRANGE", redis_vrange_cmd, cluster_mbulk_resp, 1);
|
||||
}
|
||||
|
||||
PHP_METHOD(RedisCluster, vrem) {
|
||||
CLUSTER_PROCESS_KW_CMD("VREM", redis_kv_cmd, cluster_long_resp, 0);
|
||||
}
|
||||
|
||||
@@ -1108,6 +1108,19 @@ class RedisCluster {
|
||||
*/
|
||||
public function vrandmember(string $key, int $count = 0): RedisCluster|array|string|false;
|
||||
|
||||
/**
|
||||
* Retreive a lexographical range of elements from a vector set
|
||||
*
|
||||
* @param string $key The vector set to query.
|
||||
* @param string $min The minimum element to return.
|
||||
* @param string $max The maximum element to return.
|
||||
* @param int $count An optional maximum number of elements to return.
|
||||
*
|
||||
* @return RedisCluster|array|false An array of elements in the specified range.`
|
||||
*/
|
||||
public function vrange(string $key, string $min, string $max, int $count = -1): RedisCluster|array|false;
|
||||
|
||||
|
||||
/**
|
||||
* @see Redis::vrem
|
||||
*/
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: c8d6113b07ba9386e41ab8513190c87415676bd0 */
|
||||
* Stub hash: d504e84c671162c4ec78aa1e6bb5a47c695ee90d */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
|
||||
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
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_vrange, 0, 3, RedisCluster, MAY_BE_ARRAY|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, min, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, max, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_vrem, 0, 2, RedisCluster, MAY_BE_LONG|MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, member, IS_MIXED, 0)
|
||||
@@ -1377,6 +1384,7 @@ ZEND_METHOD(RedisCluster, vinfo);
|
||||
ZEND_METHOD(RedisCluster, vismember);
|
||||
ZEND_METHOD(RedisCluster, vemb);
|
||||
ZEND_METHOD(RedisCluster, vrandmember);
|
||||
ZEND_METHOD(RedisCluster, vrange);
|
||||
ZEND_METHOD(RedisCluster, vrem);
|
||||
ZEND_METHOD(RedisCluster, vlinks);
|
||||
ZEND_METHOD(RedisCluster, vgetattr);
|
||||
@@ -1633,6 +1641,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
|
||||
ZEND_ME(RedisCluster, vismember, arginfo_class_RedisCluster_vismember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vemb, arginfo_class_RedisCluster_vemb, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrandmember, arginfo_class_RedisCluster_vrandmember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrange, arginfo_class_RedisCluster_vrange, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrem, arginfo_class_RedisCluster_vrem, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vlinks, arginfo_class_RedisCluster_vlinks, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vgetattr, arginfo_class_RedisCluster_vgetattr, ZEND_ACC_PUBLIC)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: c8d6113b07ba9386e41ab8513190c87415676bd0 */
|
||||
* Stub hash: d504e84c671162c4ec78aa1e6bb5a47c695ee90d */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, name)
|
||||
@@ -771,6 +771,13 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_RedisCluster_vrandmember arginfo_class_RedisCluster_lpop
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_vrange, 0, 0, 3)
|
||||
ZEND_ARG_INFO(0, key)
|
||||
ZEND_ARG_INFO(0, min)
|
||||
ZEND_ARG_INFO(0, max)
|
||||
ZEND_ARG_INFO(0, count)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_RedisCluster_vrem arginfo_class_RedisCluster_hexists
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster_vlinks, 0, 0, 2)
|
||||
@@ -1206,6 +1213,7 @@ ZEND_METHOD(RedisCluster, vinfo);
|
||||
ZEND_METHOD(RedisCluster, vismember);
|
||||
ZEND_METHOD(RedisCluster, vemb);
|
||||
ZEND_METHOD(RedisCluster, vrandmember);
|
||||
ZEND_METHOD(RedisCluster, vrange);
|
||||
ZEND_METHOD(RedisCluster, vrem);
|
||||
ZEND_METHOD(RedisCluster, vlinks);
|
||||
ZEND_METHOD(RedisCluster, vgetattr);
|
||||
@@ -1462,6 +1470,7 @@ static const zend_function_entry class_RedisCluster_methods[] = {
|
||||
ZEND_ME(RedisCluster, vismember, arginfo_class_RedisCluster_vismember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vemb, arginfo_class_RedisCluster_vemb, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrandmember, arginfo_class_RedisCluster_vrandmember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrange, arginfo_class_RedisCluster_vrange, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vrem, arginfo_class_RedisCluster_vrem, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vlinks, arginfo_class_RedisCluster_vlinks, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(RedisCluster, vgetattr, arginfo_class_RedisCluster_vgetattr, ZEND_ACC_PUBLIC)
|
||||
|
||||
+26
-5
@@ -5856,14 +5856,16 @@ int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
}
|
||||
|
||||
/* X[REV]RANGE key start end [COUNT count] */
|
||||
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot,
|
||||
void **ctx)
|
||||
static int
|
||||
redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, zend_bool have_count_literal, char **cmd,
|
||||
int *cmd_len, short *slot, void **ctx)
|
||||
{
|
||||
smart_string cmdstr = {0};
|
||||
char *key, *start, *end;
|
||||
size_t keylen, startlen, endlen;
|
||||
zend_long count = -1;
|
||||
int argc;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|l", &key, &keylen,
|
||||
&start, &startlen, &end, &endlen, &count)
|
||||
@@ -5872,13 +5874,16 @@ int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
redis_cmd_init_sstr(&cmdstr, 3 + (2 * (count > -1)), kw, strlen(kw));
|
||||
argc = 3 + ((have_count_literal ? 2 : 1) * (count > -1));
|
||||
redis_cmd_init_sstr(&cmdstr, argc, kw, strlen(kw));
|
||||
|
||||
redis_cmd_append_sstr_key(&cmdstr, key, keylen, redis_sock, slot);
|
||||
redis_cmd_append_sstr(&cmdstr, start, startlen);
|
||||
redis_cmd_append_sstr(&cmdstr, end, endlen);
|
||||
|
||||
if (count > -1) {
|
||||
redis_cmd_append_sstr(&cmdstr, ZEND_STRL("COUNT"));
|
||||
if (have_count_literal)
|
||||
redis_cmd_append_sstr(&cmdstr, ZEND_STRL("COUNT"));
|
||||
redis_cmd_append_sstr_long(&cmdstr, count);
|
||||
}
|
||||
|
||||
@@ -5887,6 +5892,22 @@ int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot,
|
||||
void **ctx)
|
||||
{
|
||||
return redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
|
||||
redis_sock, kw, 1, cmd, cmd_len, slot, ctx);
|
||||
}
|
||||
|
||||
int redis_vrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot,
|
||||
void **ctx)
|
||||
{
|
||||
return redis_xrange_generic_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
|
||||
redis_sock, kw, 0, cmd, cmd_len, slot, ctx);
|
||||
}
|
||||
|
||||
/* Helper function to take an associative array and append the Redis
|
||||
* STREAMS stream [stream...] id [id ...] arguments to a command string. */
|
||||
static int
|
||||
|
||||
@@ -191,6 +191,9 @@ int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
|
||||
|
||||
int redis_vrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
|
||||
|
||||
int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
|
||||
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 26d337d9f4984fe9e2c15c4245620494cb6ac24e */
|
||||
* Stub hash: 619374bbad94b8a9992f9c11abd12362e07359d0 */
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
|
||||
ZEND_ARG_INFO(0, options)
|
||||
@@ -972,6 +972,13 @@ ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_Redis_vrandmember arginfo_class_Redis_lPop
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_vrange, 0, 0, 3)
|
||||
ZEND_ARG_INFO(0, key)
|
||||
ZEND_ARG_INFO(0, min)
|
||||
ZEND_ARG_INFO(0, max)
|
||||
ZEND_ARG_INFO(0, count)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_class_Redis_vrem arginfo_class_Redis_hGet
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_vsetattr, 0, 0, 3)
|
||||
@@ -1369,6 +1376,7 @@ ZEND_METHOD(Redis, vinfo);
|
||||
ZEND_METHOD(Redis, vismember);
|
||||
ZEND_METHOD(Redis, vemb);
|
||||
ZEND_METHOD(Redis, vrandmember);
|
||||
ZEND_METHOD(Redis, vrange);
|
||||
ZEND_METHOD(Redis, vrem);
|
||||
ZEND_METHOD(Redis, vsetattr);
|
||||
ZEND_METHOD(Redis, vgetattr);
|
||||
@@ -1657,6 +1665,7 @@ static const zend_function_entry class_Redis_methods[] = {
|
||||
ZEND_ME(Redis, vismember, arginfo_class_Redis_vismember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vemb, arginfo_class_Redis_vemb, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrandmember, arginfo_class_Redis_vrandmember, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrange, arginfo_class_Redis_vrange, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vrem, arginfo_class_Redis_vrem, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vsetattr, arginfo_class_Redis_vsetattr, ZEND_ACC_PUBLIC)
|
||||
ZEND_ME(Redis, vgetattr, arginfo_class_Redis_vgetattr, ZEND_ACC_PUBLIC)
|
||||
|
||||
@@ -7887,6 +7887,25 @@ class Redis_Test extends TestSuite {
|
||||
);
|
||||
}
|
||||
|
||||
public function testVRange() {
|
||||
if ($this->haveCommand('VRANGE') === false)
|
||||
$this->markTestSkipped();
|
||||
|
||||
$this->assertIsInt($this->redis->del('v'));
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$this->assertEquals(1, $this->redis->vadd('v', [$i / 10, $i / 10], "e{$i}"));
|
||||
}
|
||||
|
||||
$res = $this->redis->vrange('v', '-', '+');
|
||||
$this->assertIsArray($res);
|
||||
$this->assertEquals(10, count($res));
|
||||
|
||||
$res = $this->redis->vrange('v', '-', '+', 3);
|
||||
$this->assertIsArray($res);
|
||||
$this->assertEquals(3, count($res));
|
||||
}
|
||||
|
||||
public function testInvalidAuthArgs() {
|
||||
$client = $this->newInstance();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user