bungle / lua-resty-session

Session library for OpenResty – flexible and secure
BSD 2-Clause "Simplified" License
319 stars 111 forks source link

Session save have no effect after output ? #152

Open Flash-ang opened 1 year ago

Flash-ang commented 1 year ago

Test Code :

local session = require "resty.session".start{ cookie = { domain = "localhost" }, secret = "623q4hR325t36VsCD3g567922IC0073T" }

function list()
    ngx.say( 'list session.data : ' );
    for k, v in pairs(session.data) do
        ngx.say( 'session.data : ', k, ' = ', tostring(v) )
    end
    ngx.say();
end

if( session.data.uid == nil ) then
    session.data.uid = 0;
else
    session.data.uid = session.data.uid + 1
end

session:save()

list()

session.data.uid = session.data.uid + 100000
session.data.name = "f3() + " .. tostring(session.data.name )
session:save()

list()
Output (#1 round clear cache) : 
list session.data : 
session.data : uid = 0

list session.data : 
session.data : name = f3() + nil
session.data : uid = 100000

Output (#2 round press refresh) : 
list session.data : 
session.data : uid = 1

list session.data : 
session.data : uid = 100001
session.data : name = f3() + nil

Output (#3 round press refresh) : 
list session.data : 
session.data : uid = 2

list session.data : 
session.data : uid = 100002
session.data : name = f3() + nil

if this is the design, may state in documentation.