我们可以在数据库中存储会话吗

时间:2022-06-11 16:56:37

Can we store session in database Mysql not in memory using passport module.

我们可以使用护照模块在数据库Mysql中存储会话。

I am using nodejs, express and mysql

我正在使用nodejs,express和mysql

Thanks

谢谢

1 个解决方案

#1


3  

Passport module doesn't provide sessions to your application, it uses connect or express session.

Passport模块不为您的应用程序提供会话,它使用connect或express会话。

connect/express sessions may (and should!) be persistent and there are plenty of session stores available on npm.

连接/表达会话可以(并且应该!)持久,并且在npm上有很多会话存储可用。

With a quick search I found two implementations of connect/express mysql session store:

通过快速搜索,我发现了两个connect / express mysql会话存储的实现:

Just take any one of them and use as your session store with express-session (or conncect.session):

只需将它们中的任何一个用作具有快速会话(或conncect.session)的会话存储:

var express = require('express');
var session = require('express-session');
var SessionStore = require('express-mysql-session')

var app = express();
var sessionStore = new SessionStore(/*options*/);

app.use(session({
    key: 'session_cookie_name',
    secret: 'session_cookie_secret',
    store: sessionStore,
    resave: true,
    saveUninitialized: true
}))

#1


3  

Passport module doesn't provide sessions to your application, it uses connect or express session.

Passport模块不为您的应用程序提供会话,它使用connect或express会话。

connect/express sessions may (and should!) be persistent and there are plenty of session stores available on npm.

连接/表达会话可以(并且应该!)持久,并且在npm上有很多会话存储可用。

With a quick search I found two implementations of connect/express mysql session store:

通过快速搜索,我发现了两个connect / express mysql会话存储的实现:

Just take any one of them and use as your session store with express-session (or conncect.session):

只需将它们中的任何一个用作具有快速会话(或conncect.session)的会话存储:

var express = require('express');
var session = require('express-session');
var SessionStore = require('express-mysql-session')

var app = express();
var sessionStore = new SessionStore(/*options*/);

app.use(session({
    key: 'session_cookie_name',
    secret: 'session_cookie_secret',
    store: sessionStore,
    resave: true,
    saveUninitialized: true
}))