summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorfilipe oliveira <filipecosta.90@gmail.com>2022-12-05 06:33:53 +0000
committerGitHub <noreply@github.com>2022-12-05 08:33:53 +0200
commit2d80cd7840d4a6ac0305c9192fc6a5de43759570 (patch)
treec4a9c650ea7fd32c61859010d2e64318af710156 /tests
parent61c85a2b2081dffaf45eb8c6b7754b8d9a80c60d (diff)
downloadredis-2d80cd7840d4a6ac0305c9192fc6a5de43759570.tar.gz
Reintroduce lua argument cache in luaRedisGenericCommand removed in v7.0 (#11541)
This mechanism aims to reduce calls to malloc and free when preparing the arguments the script sends to redis commands. This is a mechanism was originally implemented in 48c49c4 and 4f68655, and was removed in #10220 (thinking it's not needed and that it has no impact), but it now turns out it was wrong, and it indeed provides some 5% performance improvement. The implementation is a little bit too simplistic, it assumes consecutive calls use the same size in the same arg index, but that's arguably sufficient since it's only aimed at caching very small things. We could even consider always pre-allocating args to the full LUA_CMD_OBJCACHE_MAX_LEN (64 bytes) rather than the right size for the argument, that would increase the chance they'll be able to be re-used. But in some way this is already happening since we're using sdsalloc, which in turn uses s_malloc_usable and takes ownership of the full side of the allocation, so we are padded to the allocator bucket size. Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: sundb <sundbcn@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/scripting.tcl15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl
index ca9422787..fa617d7fe 100644
--- a/tests/unit/scripting.tcl
+++ b/tests/unit/scripting.tcl
@@ -1956,5 +1956,20 @@ start_server {tags {"scripting"}} {
r eval {local status, res = pcall(function() return foo end); return 'status: ' .. tostring(status) .. ' result: ' .. res} 0
]
}
+
+ test "LUA test pcall with non string/integer arg" {
+ assert_error "ERR Lua redis lib command arguments must be strings or integers*" {
+ r eval {
+ local x={}
+ return redis.call("ping", x)
+ } 0
+ }
+ # run another command, to make sure the cached argv array survived
+ assert_equal [
+ r eval {
+ return redis.call("ping", "asdf")
+ } 0
+ ] {asdf}
+ }
}