Redis不删除会话密钥(Redis Not Deleting Session Keys)

编程入门 行业动态 更新时间:2024-10-22 11:27:16
Redis不删除会话密钥(Redis Not Deleting Session Keys)

我正在使用Redis来存储我的ExpressJS应用程序的会话数据,并且过去遇到了一些问题,其中持久性cookie使我的用户登录导致开发问题。 我试图用redis-cli清除会话数据,但是尽管运行了DEL KEYS *并且给出了(integer) 0响应,我仍然看到在运行KEYS *时会话出现。 任何人都可以帮我删除这些数据吗?

例:

127.0.0.1:6379> KEYS * 1) "sess:O7pchKqe-n7NUhP3lBANaf7LMjJG0U0a" 2) "sess:tSyQCCISPBpH88zT3MJjHw2tidttMdRs" 127.0.0.1:6379> DEL KEYS * (integer) 0 127.0.0.1:6379> KEYS * 1) "sess:O7pchKqe-n7NUhP3lBANaf7LMjJG0U0a" 2) "sess:tSyQCCISPBpH88zT3MJjHw2tidttMdRs"

存储会话数据的ExpressJS代码:

var express = require('express'); var app = express(); var passport = require('passport'); var bodyParser = require('body-parser'); var cookieParser = require('cookie-parser'); var session = require('express-session'); var RedisStore = require('connect-redis')(session); var path = require('path'); //Port Setting var port = process.env.PORT || 3000; //Set Morgan as Logger app.use(morgan('dev')); //Extract POST Data app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); //Session Cookie app.use(cookieParser()); app.use(session({ store: new RedisStore({ host: '127.0.0.1', port: 6379 }), secret: 'super-secret', resave: true, saveUninitialized: true, cookie: { httpOnly: true, secure: false //turn to true on production once https is in place } }));

I am using Redis to store my session data for my ExpressJS application and in the past have run into some issues where the persistent cookie is keeping my user logged in causing issues with development. I have tried to clear my session data with the redis-cli, but despite running DEL KEYS * and being given the (integer) 0 response, I still see the sessions appear when I run KEYS *. Can anyone help me with removing that data?

Example:

127.0.0.1:6379> KEYS * 1) "sess:O7pchKqe-n7NUhP3lBANaf7LMjJG0U0a" 2) "sess:tSyQCCISPBpH88zT3MJjHw2tidttMdRs" 127.0.0.1:6379> DEL KEYS * (integer) 0 127.0.0.1:6379> KEYS * 1) "sess:O7pchKqe-n7NUhP3lBANaf7LMjJG0U0a" 2) "sess:tSyQCCISPBpH88zT3MJjHw2tidttMdRs"

ExpressJS code storing the session data:

var express = require('express'); var app = express(); var passport = require('passport'); var bodyParser = require('body-parser'); var cookieParser = require('cookie-parser'); var session = require('express-session'); var RedisStore = require('connect-redis')(session); var path = require('path'); //Port Setting var port = process.env.PORT || 3000; //Set Morgan as Logger app.use(morgan('dev')); //Extract POST Data app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); //Session Cookie app.use(cookieParser()); app.use(session({ store: new RedisStore({ host: '127.0.0.1', port: 6379 }), secret: 'super-secret', resave: true, saveUninitialized: true, cookie: { httpOnly: true, secure: false //turn to true on production once https is in place } }));

最满意答案

(从评论转移)

我想你想要flushdb删除所有密钥。 del没有办法指定通配符,因此del keys *将尝试删除两个键:一个称为“keys”,另一个称为“*”。 响应0表示删除了0个键。

(transferring from comment)

I think you want flushdb to delete all keys. del doesn't have a way to specify a wildcard, so del keys * will try to delete two keys: one called "keys" and one called "*". The response 0 means that 0 keys were deleted.

更多推荐

本文发布于:2023-04-28 00:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329683.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   Redis   Deleting   Keys   Session

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!