openresty 在不影响 老化时间的前提下,怎么修改共享内存的string 类型的值?

82 views
Skip to first unread message

dym5...@gmail.com

unread,
Sep 18, 2016, 4:06:13 AM9/18/16
to openresty
我在在共享内存存储了一个这样的值:
(“192.168.1.1”,"['cookie1','cookie2','cookie3']",300)

问题是:
          现在想修改存储的值为 "['cookie1','cookie2','cookie3','cookie4']" 而且老化时间问当前的老花化时间,而不用初始化为300?

YuanSheng Wang

unread,
Sep 22, 2016, 11:04:23 AM9/22/16
to open...@googlegroups.com
https://github.com/iresty/nginx-lua-module-zh-wiki#ngxshareddictset

可以使用 flags 存储最终截止有效期,通过 get 方法获取到 flags,与当前时间的差值就能获取到这个 key 的剩余有效期。

这时候就可以完成更新 value 并且可以维持过期时间的效果了。

ngx.shared.DICT.set

语法: success, err, forcible = ngx.shared.DICT:set(key, value, exptime?, flags?)

环境: init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*

ngx.shared.DICT.get

语法: value, flags = ngx.shared.DICT:get(key)


--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html



--

YuanSheng Wang
---------------------------------------
OpenResty lover ^_^
Reply all
Reply to author
Forward
0 new messages