我想運行一個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