Unverified Commit 0a8e5469 authored by opt-m's avatar opt-m Committed by GitHub
Browse files

Fix get # option in sort command (#13608)



From 7.4, Redis allows `GET` options in cluster mode when the pattern maps to
the same slot as the key, but GET # pattern that represents key itself is missed.
This commit resolves it, bug report #13607.

---------
Co-authored-by: default avatarYuan Wang <yuan.wang@redis.com>
parent 4f8cdc2a
......@@ -241,8 +241,12 @@ void sortCommandGeneric(client *c, int readonly) {
} else if (!strcasecmp(c->argv[j]->ptr,"get") && leftargs >= 1) {
/* If GET is specified with a real pattern, we can't accept it in cluster mode,
* unless we can make sure the keys formed by the pattern are in the same slot
* as the key to sort. */
if (server.cluster_enabled && patternHashSlot(c->argv[j+1]->ptr, sdslen(c->argv[j+1]->ptr)) != getKeySlot(c->argv[1]->ptr)) {
* as the key to sort. The pattern # represents the key itself, so just skip
* pattern slot check. */
if (server.cluster_enabled &&
strcmp(c->argv[j+1]->ptr, "#") &&
patternHashSlot(c->argv[j+1]->ptr, sdslen(c->argv[j+1]->ptr)) != getKeySlot(c->argv[1]->ptr))
{
addReplyError(c, "GET option of SORT denied in Cluster mode when "
"keys formed by the pattern may be in different slots.");
syntax_error++;
......
......@@ -73,7 +73,7 @@ start_server {
set result [create_random_dataset 16 lpush]
test "SORT GET #" {
assert_equal [lsort -integer $result] [r sort tosort GET #]
} {} {cluster:skip}
}
foreach command {SORT SORT_RO} {
test "$command GET <const>" {
......@@ -393,6 +393,11 @@ start_cluster 1 0 {tags {"external:skip cluster sort"}} {
r sort "{a}mylist" by "{a}by*" get "{a}get*"
} {30 200 100}
test "sort get # in cluster mode" {
assert_equal [r sort "{a}mylist" by "{a}by*" get # ] {3 1 2}
r sort "{a}mylist" by "{a}by*" get "{a}get*" get #
} {30 3 200 1 100 2}
test "sort_ro by in cluster mode" {
catch {r sort_ro "{a}mylist" by by*} e
assert_match {ERR BY option of SORT denied in Cluster mode when *} $e
......@@ -404,4 +409,9 @@ start_cluster 1 0 {tags {"external:skip cluster sort"}} {
assert_match {ERR GET option of SORT denied in Cluster mode when *} $e
r sort_ro "{a}mylist" by "{a}by*" get "{a}get*"
} {30 200 100}
test "sort_ro get # in cluster mode" {
assert_equal [r sort_ro "{a}mylist" by "{a}by*" get # ] {3 1 2}
r sort_ro "{a}mylist" by "{a}by*" get "{a}get*" get #
} {30 3 200 1 100 2}
}
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