openresty启动报attempt to call method 'ttl' (a nil value)错误,openrestynil


今天测试openresty中ngx.shared.DICT的字段剩余有效期,直接:

status_dict:safe_set("test","ttest",60)
 local ttime = status_dict:ttl("test")

但是启动openresty就会报attempt to call method 'ttl' (a nil value)错误,后来查看openresty 文档https://github.com/openresty/lua-nginx-module ,得知要用 ngx.shared.DICT.ttl 这个方法,需要 引入 resty.core 这个包,

即在需要用到ngx.shared.DICT.ttl 这个方法的地方加入 require "resty.core" 即可解决

相关内容

    暂无相关文章