Closed tw-bert closed 6 years ago
@tw-bert, the first result (INFO
) is by design; the second is a bug and should be fixed with the following patch:
diff --git a/redis.lua b/redis.lua
index 752f594..d459691 100644
--- a/redis.lua
+++ b/redis.lua
@@ -1573,7 +1573,7 @@ local package = {
name = "Redis",
description = "Integrates with Redis.",
author = "Paul Kulchenko",
- version = 0.33,
+ version = 0.34,
dependencies = "1.30",
onRegister = function(self)
@@ -1650,7 +1650,7 @@ local function getreply(response)
local msg = table.concat(getval(response, "<reply>", "%s") or {}, ",")
-- add proper quoting to those messages that may be truncated because of `maxlen` limit
if msg:find('^"') and not msg:find('"$') then msg = msg..'"' end
- return "return {"..(msg == "NULL" and "'nil'" or msg).."}"
+ return ("return {%s}"):format(msg == "NULL" and "'nil'" or ("%q"):format(msg))
end
local function geterror(response)
local err = getval(type(response) == 'table' and response or {response}, "<error>")
Let me know if this worked for you.
@pkulchenko , statements like INFO MEMORY
are nicely formatted before this patch, is it possible to retain that? After the patch, it's just a long string with escaped chars.
@tw-bert, agree, this should be a better patch:
diff --git a/redis.lua b/redis.lua
index d459691..f2e701e 100644
--- a/redis.lua
+++ b/redis.lua
@@ -1650,7 +1650,13 @@ local function getreply(response)
local msg = table.concat(getval(response, "<reply>", "%s") or {}, ",")
-- add proper quoting to those messages that may be truncated because of `maxlen` limit
if msg:find('^"') and not msg:find('"$') then msg = msg..'"' end
- return "return {"..(msg == "NULL" and "'nil'" or msg).."}"
+ return ("return {%s}"):format(
+ -- show returned NULL as `nil`
+ msg == "NULL" and "'nil'" or
+ -- show array (`[...]`) results from commands like `@hgetall something` as is
+ msg:find("^%[.+%]$") and ("%q"):format(msg) or
+ msg
+ )
end
local function geterror(response)
local err = getval(type(response) == 'table' and response or {response}, "<error>")
I didn't want to have array-specific logic in it, but it seems like it may be necessary in this case.
@pkulchenko This patch works fine
redis.lua: version 0.33
@
.redis.call()
Gist that replicates both small issues: