Merge pull request #1155 from moteus/cache_delete

Fix. `cache.del` method.
This commit is contained in:
FusionPBX 2015-09-15 21:04:59 -06:00
commit 0b77b33d9a
1 changed files with 23 additions and 2 deletions

View File

@ -51,11 +51,13 @@ end
function Cache.set(key, value, expire)
value = value:gsub("'", "'"):gsub("\\", "\\\\")
expire = expire and tostring(expire) or ""
return check_error(api:execute("memcache", "set " .. key .. " '" .. value .. "' " .. expire))
local ok, err = check_error(api:execute("memcache", "set " .. key .. " '" .. value .. "' " .. expire))
if not ok then return nil, err end
return ok == '+OK'
end
function Cache.del(key)
local result, err = check_error(api:execute("memcache", "set " .. key .. " '" .. value .. "' " .. expire))
local result, err = check_error(api:execute("memcache", "delete " .. key))
if not result then
if err == 'NOT FOUND' then
return true
@ -65,4 +67,23 @@ function Cache.del(key)
return result == '+OK'
end
function Cache._self_test()
assert(Cache.support())
Cache.del("a")
local ok, err = Cache.get("a")
assert(nil == ok)
assert(err == "NOT FOUND")
local s = "hello \\ ' world"
assert(true == Cache.set("a", s))
assert(s == Cache.get("a"))
assert(true == Cache.del("a"))
end
-- if debug.self_test then
-- Cache._self_test()
-- end
return Cache