我正在尝试运行一个redis lua模拟项目来测试我的redis lua代码。但是很明显,redis-mock项目中有bug。
当我在测试代码中调用redis.call('hget', 'foo', 'bar')时,redis mock在从RedisLua.lua#20调用的hash.lua#22处抛出一个assert错误
-- RedisLua.lua
local call = function(self)
return (function(cmd, ...)
cmd = string.lower(cmd)
local arg = {...}
local ret = self.db[cmd](self.db, unpack(arg)) -- line 20
if self.RedisLua_VERBOSE then
print(cmd .. "( " .. table.concat(arg, " ") .. " ) === ".. tostring(ret))
end
return ret
end)
end
-- hash.lua
function RedisDb:hget(self,k,k2)
assert((type(k2) == "string")) -- # line 22
local x = RedisDb.xgetr(self,k,"hash")
return x[k2]
end经过跟踪,我发现self是'foo',k是'bar',k2实际上是nil,我该如何修复这个bug,k应该是foo,k2应该是<代码>D13
发布于 2013-03-13 15:27:29
我认为您需要调用redis:call('hget', 'foo', 'bar')或等效的redis.call(redis,'hget','foo','bar'),而不是redis.call('hget', 'foo', 'bar')。
发布于 2013-03-13 17:12:05
回答我自己的问题。
当定义为:时,不需要self。
-- hash.lua
function RedisDb:hget(self,k,k2)
assert((type(k2) == "string")) -- # line 22
local x = RedisDb.xgetr(self,k,"hash")
return x[k2]
end更改为
-- hash.lua
function RedisDb:hget(k,k2)
assert((type(k2) == "string")) -- # line 22
local x = RedisDb:xgetr(k,"hash")
return x[k2]
endhttps://stackoverflow.com/questions/15379174
复制相似问题