面向 OpenResty 的 session 库:lua-resty-session
jopen
9年前
lua-resty-session 是一个面向 OpenResty 的安全和灵活的 session 库,它实现了 Secure Cookie Protocol。
更详细的说明请查看
https://github.com/bungle/lua-resty-session/blob/master/README.md
http { server { listen 8080; server_name localhost; default_type text/html; location / { content_by_lua ' ngx.say("<html><body><a href=/start>Start the test</a>!</body></html>") '; } location /start { content_by_lua ' local session = require "resty.session".start() session.data.name = "OpenResty Fan" session:save() ngx.say("<html><body>Session started. ", "<a href=/test>Check if it is working</a>!</body></html>") '; } location /test { content_by_lua ' local session = require "resty.session".open() ngx.say("<html><body>Session was started by <strong>", session.data.name or "Anonymous", "</strong>! <a href=/destroy>Destroy the session</a>.</body></html>") '; } location /destroy { content_by_lua ' local session = require "resty.session".start() session:destroy() ngx.say("<html><body>Session was destroyed. ", "<a href=/check>Is it really so</a>?</body></html>") '; } location /check { content_by_lua ' local session = require "resty.session".open() ngx.say("<html><body>Session was really destroyed, you are known as ", "<strong>", session.data.name or "Anonymous", "</strong>! <a href=/>Start again</a>.</body></html>") '; } } }