From: antirez Date: Tue, 4 Sep 2012 23:12:41 +0000 (+0200) Subject: Scripting: Force SORT BY constant determinism inside SORT itself. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/36741b2c818a95e8ef167818271614ee6b1bc414?hp=36741b2c818a95e8ef167818271614ee6b1bc414 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 ;) ---