summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-09-05 01:12:41 +0200
committerantirez <antirez@gmail.com>2012-09-05 01:17:49 +0200
commit36741b2c818a95e8ef167818271614ee6b1bc414 (patch)
treeaf1b404cb7b113c0a3ef18f2f5396f171b2d1c89 /tests
parent9bd0e097aa19b697757cdb73dd447e2c6f4960c6 (diff)
downloadredis-36741b2c818a95e8ef167818271614ee6b1bc414.tar.gz
Scripting: Force SORT BY constant determinism inside SORT itself.
SORT is able to return (faster than when ordering) unordered output if the "BY" clause is used with a constant value. However we try to play well with scripting requirements of determinism providing always sorted outputs when SORT (and other similar commands) are called by Lua scripts. However we used the general mechanism in place in scripting in order to reorder SORT output, that is, if the command has the "S" flag set, the Lua scripting engine will take an additional step when converting a multi bulk reply to Lua value, calling a Lua sorting function. This is suboptimal as we can do it faster inside SORT itself. This is also broken as issue #545 shows us: basically when SORT is used with a constant BY, and additionally also GET is used, the Lua scripting engine was trying to order the output as a flat array, while it was actually a list of key-value pairs. What we do know is to recognized if the caller of SORT is the Lua client (since we can check this using the REDIS_LUA_CLIENT flag). If so, and if a "don't sort" condition is triggered by the BY option with a constant string, we force the lexicographical sorting. This commit fixes this bug and improves the performance, and at the same time simplifies the implementation. This does not mean I'm smart today, it means I was stupid when I committed the original implementation ;)
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/scripting.tcl8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl
index 6d60e4198..057918716 100644
--- a/tests/unit/scripting.tcl
+++ b/tests/unit/scripting.tcl
@@ -203,23 +203,23 @@ start_server {tags {"scripting"}} {
r eval {return redis.call('smembers','myset')} 0
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
- test "SORT is normally not re-ordered by the scripting engine" {
+ test "SORT is normally not alpha re-ordered for the scripting engine" {
r del myset
r sadd myset 1 2 3 4 10
r eval {return redis.call('sort','myset','desc')} 0
} {10 4 3 2 1}
- test "SORT BY <constant> output gets ordered by scripting" {
+ test "SORT BY <constant> output gets ordered for scripting" {
r del myset
r sadd myset a b c d e f g h i l m n o p q r s t u v z aa aaa azz
r eval {return redis.call('sort','myset','by','_')} 0
} {a aa aaa azz b c d e f g h i l m n o p q r s t u v z}
- test "SORT output containing NULLs is well handled by scripting" {
+ test "SORT BY <constant> with GET gets ordered for scripting" {
r del myset
r sadd myset a b c
r eval {return redis.call('sort','myset','by','_','get','#','get','_:*')} 0
- } {{} {} {} a b c}
+ } {a {} b {} c {}}
test "redis.sha1hex() implementation" {
list [r eval {return redis.sha1hex('')} 0] \