我想运行一个redis lua模拟项目来测试我的redis lua代码。但显然,redis-mock项目中存在缺陷。如何调用变量参数方法与解压
当我在我的测试代码中调用redis.call('hget', 'foo', 'bar')
,Redis的嘲笑在hash.lua#22抛出断言错误是由RedisLua.lua#20
-- 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
应'bar'
无需想着那里。 :P – hjpotter92 2013-03-13 07:32:35
这是一个模拟或Redis,其中Redis官方定义'redis.call(cmd,...)',如果模拟不遵循官方API,那么它是没有意义的。 – 2013-03-13 08:44:37