Unverified Commit b5029dfd authored by Jonah H. Harris's avatar Jonah H. Harris Committed by GitHub
Browse files

Add ZRANGESTORE command, and improve ZSTORE command (#7844)



Add ZRANGESTORE command, and improve ZSTORE command to deprecated Z[REV]RANGE[BYSCORE|BYLEX].

Syntax for the new ZRANGESTORE command:
ZRANGESTORE [BYSCORE | BYLEX] [REV] [LIMIT offset count]

New syntax for ZRANGE:
ZRANGE [BYSCORE | BYLEX] [REV] [WITHSCORES] [LIMIT offset count]

Old syntax for ZRANGE:
ZRANGE [WITHSCORES]

Other ZRANGE commands remain unchanged.

The implementation uses common code for all of these, by utilizing a consumer interface that in one
command response to the client, and in the other command stores a zset key.
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent cfcd0fa6
......@@ -464,6 +464,10 @@ struct redisCommand redisCommandTable[] = {
"read-only @sortedset",
0,NULL,1,1,1,0,0,0},
{"zrangestore",zrangestoreCommand,-5,
"write use-memory @sortedset",
0,NULL,1,2,1,0,0,0},
{"zrangebyscore",zrangebyscoreCommand,-4,
"read-only @sortedset",
0,NULL,1,1,1,0,0,0},
......
......@@ -2517,6 +2517,7 @@ void zinterstoreCommand(client *c);
void zdiffstoreCommand(client *c);
void zunionCommand(client *c);
void zinterCommand(client *c);
void zrangestoreCommand(client *c);
void zdiffCommand(client *c);
void zscanCommand(client *c);
void hkeysCommand(client *c);
......
This diff is collapsed.
......@@ -1472,4 +1472,86 @@ start_server {tags {"zset"}} {
}
r config set zset-max-ziplist-entries $original_max
}
test {ZRANGESTORE basic} {
r flushall
r zadd z1 1 a 2 b 3 c 4 d
set res [r zrangestore z2 z1 0 -1]
assert_equal $res 4
r zrange z2 0 -1 withscores
} {a 1 b 2 c 3 d 4}
test {ZRANGESTORE range} {
set res [r zrangestore z2 z1 1 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
} {b 2 c 3}
test {ZRANGESTORE BYLEX} {
set res [r zrangestore z2 z1 \[b \[c BYLEX]
assert_equal $res 2
r zrange z2 0 -1 withscores
} {b 2 c 3}
test {ZRANGESTORE BYSCORE} {
set res [r zrangestore z2 z1 1 2 BYSCORE]
assert_equal $res 2
r zrange z2 0 -1 withscores
} {a 1 b 2}
test {ZRANGESTORE BYSCORE LIMIT} {
set res [r zrangestore z2 z1 0 5 BYSCORE LIMIT 0 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
} {a 1 b 2}
test {ZRANGESTORE BYSCORE REV LIMIT} {
set res [r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2]
assert_equal $res 2
r zrange z2 0 -1 withscores
} {c 3 d 4}
test {ZRANGE BYSCORE REV LIMIT} {
r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
} {d 4 c 3}
test {ZRANGESTORE - empty range} {
set res [r zrangestore z2 z1 5 6]
assert_equal $res 0
r exists z2
} {0}
test {ZRANGESTORE BYLEX - empty range} {
set res [r zrangestore z2 z1 \[f \[g BYLEX]
assert_equal $res 0
r exists z2
} {0}
test {ZRANGESTORE BYSCORE - empty range} {
set res [r zrangestore z2 z1 5 6 BYSCORE]
assert_equal $res 0
r exists z2
} {0}
test {ZRANGE BYLEX} {
r zrange z1 \[b \[c BYLEX
} {b c}
test {ZRANGESTORE invalid syntax} {
catch {r zrangestore z2 z1 0 -1 limit 1 2} err
assert_match "*syntax*" $err
catch {r zrangestore z2 z1 0 -1 WITHSCORES} err
assert_match "*syntax*" $err
}
test {ZRANGE invalid syntax} {
catch {r zrange z1 0 -1 limit 1 2} err
assert_match "*syntax*" $err
catch {r zrange z1 0 -1 BYLEX WITHSCORES} err
assert_match "*syntax*" $err
catch {r zrevrange z1 0 -1 BYSCORE} err
assert_match "*syntax*" $err
catch {r zrangebyscore z1 0 -1 REV} err
assert_match "*syntax*" $err
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment