我有以下代码:
const redisClient = redis.createClient({
host: 'localhost',
port: 6379,
ttl: 10
});
app.use(session({
store: new RedisStore({ client: redisClient });,
secret: 'some secret',
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
sameSite: true,
maxAge: 60*1000
}
}));
一切都会按预期进行。在后maxAge
到期,Redis的也被清除。但是,如果删除maxAge
并离开ttl
,则将永远不会清除redis,如何在不指定的情况下清除redis maxAge
,因为用户可以将cookie的值更改maxAge
为null
,然后再也不会清除redis。我可以以某种方式直接在Redis中而不是在Cookie中指定到期时间吗?还是我弄错了?先感谢您。
正如您在connect-redis
文档中的ttl
选项下看到的那样-“如果会话cookie具有过期日期,connect-redis将使用它作为TTL。”
因此,在这种情况下-cookie和redis中的密钥都将在到期时被清除。
即使客户端将以某种方式更改cookie的过期时间,它也不会影响redis(因此cookie可能通过HTTP请求发送,但服务器无法识别它)。
(您没有提到您使用的是哪个模块,我只是假设它express-session
和connect-redis
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句