如题,先添加了一个带过期时间的不存在的KEY,Value是字符串类型:
ngx.shared.DICT.set(key, “value“, 10)
我在10秒内会修改这个KEY,直接调用:
ngx.shared.DICT.set(key, “new_value“)
后来发现这个KEY一直存在,再也不会过期删除了。
location /test {
content_by_lua_block {
local value, _ = ngx.shared.dict:get('abc');
if not value then
ngx.say(ngx.now() .. ", not found");
ngx.shared.dict:set('abc', 'def', 10);
else
ngx.shared.dict:set('abc', 'xyz');
ngx.say(ngx.now() .. ", dict: abc = " .. value);
end
}
}
测试:
curl http://localhost/test && sleep 8 && curl http://localhost/test && sleep 8 && curl http://localhost/test
我理解的话目前set这个函数会覆盖已有的值,并且覆盖expire值,因为第二次调用的时候没有expire参数,所以就永远不过期了?
如果实现我类似需求(在expire时间内修改内容而不修改expire时间)的话,应该怎么使用DICT的API呢?