Merge pull request #1155 from moteus/cache_delete
Fix. `cache.del` method.
This commit is contained in:
commit
0b77b33d9a
|
|
@ -51,11 +51,13 @@ end
|
||||||
function Cache.set(key, value, expire)
|
function Cache.set(key, value, expire)
|
||||||
value = value:gsub("'", "'"):gsub("\\", "\\\\")
|
value = value:gsub("'", "'"):gsub("\\", "\\\\")
|
||||||
expire = expire and tostring(expire) or ""
|
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
|
end
|
||||||
|
|
||||||
function Cache.del(key)
|
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 not result then
|
||||||
if err == 'NOT FOUND' then
|
if err == 'NOT FOUND' then
|
||||||
return true
|
return true
|
||||||
|
|
@ -65,4 +67,23 @@ function Cache.del(key)
|
||||||
return result == '+OK'
|
return result == '+OK'
|
||||||
end
|
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
|
return Cache
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue