阅读背景:

使用Redis Cloud和Heroku正确配置节点会话存储

来源:互联网 

It is unclear what are the correct configuration parameters to use are in the situation of using Redis Cloud and Heroku, and can't find a functioning example online.

目前还不清楚在使用Redis Cloud和Heroku的情况下使用的正确配置参数是什么,并且无法在线找到正常运行的示例。

Here is my current code:

这是我目前的代码:

const express = require('express')
const session = require('express-session')
const RedisStore = require('connect-redis')(session);
...
const server = express()

server.use(bodyParser.json())
server.use(bodyParser.urlencoded({ extended: false }))

server.use(cookieParser())

server.use(session({
  secret: token_secret,
  // create new redis store.
  store: new RedisStore({ url: 'redis://rediscloud:[email protected]:11111'}),
  resave: true,
  saveUninitialized: true
}));

Should I have resave and saveUnitialized set to true or false in the case of Redis Cloud and Heroku as the session store (using express-session)?

在Redis Cloud和Heroku作为会话存储(使用快速会话)的情况下,我是否应该重新保存并将unitialized设置为true或false?

Additionally, does the cookieParser affect the session and need to be there? Or is that separate and only to parse the cookie that is coming from the client, and unrelated to the server-side session storage with Redis? Also, should the cookie parser have a secret passed into the function?

另外,cookieParser是否影响会话并且需要在那里?或者它是独立的,只是解析来自客户端的cookie,与Redis的服务器端会话存储无关?另外,cookie解析器是否应该将秘密传递给函数?

And finally, should bodyParser come before or after the server.use(session), and should urlencoded extended be set to true or false?

最后,bodyParser应该在server.use(session)之前还是之后,urlencoded extended应该设置为true还是false?

1 个解决方案

#1


0  

Let's go by parts, as Jack the Ripper said...

让我们按照部分进行操作,正如开膛手杰克所说的......

It is unclear what are the correct configuration parameters to use are in the situation of using Redis Cloud and Heroku, and can't find a functioning example online.

目前还不清楚在使用Redis Cloud和Heroku的情况下使用的正确配置参数是什么,并且无法在线找到正常运行的示例。

RedisCloud on Heroku (Node Express Example) @ GitHub

Heroku上的RedisCloud(Node Express示例)@ GitHub

Should I have resave and saveUnitialized set to true or false in the case of Redis Cloud and Heroku as the session store (using express-session)?

在Redis Cloud和Heroku作为会话存储(使用快速会话)的情况下,我是否应该重新保存并将unitialized设置为true或false?

app.use(expressSession({resave: false, saveUninitialized: false})) reduces the number of times the session store will be accessed. This benefits hardware resources and performance (Normally is better to set them to false).

app.use(expressSession({resave:false,saveUninitialized:false}))减少会话存储的访问次数。这有利于硬件资源和性能(通常最好将它们设置为false)。

Additionally, does the cookieParser affect the session and need to be there?

另外,cookieParser是否影响会话并且需要在那里?

Not anymore : express-session middleware, used to require cookie-parser, (but the current version of express-session reads/writes cookies directly).

不再是:快速会话中间件,用于需要cookie解析器,(但是当前版本的快速会话直接读取/写入cookie)。

And finally, should bodyParser come before or after the server.use(session)

最后,bodyParser应该在server.use(session)之前或之后

The body-parser middleware parses the bodies of incoming HTTP requests. Populating the req.body property which is then available in your routes and middlewares. So the order doesn't influence the behaviour.

正文解析器中间件解析传入的HTTP请求的主体。填充req.body属性,该属性随后可用于您的路由和中间件。所以订单不会影响行为。

and should urlencoded extended be set to true or false?

urlencoded扩展应该设置为true还是false?

The parsers you will need depend on the request types your server has to deal with.

您需要的解析器取决于您的服务器必须处理的请求类型。

The difference regarding extended: false and extended: true is already explained in this answer.

有关扩展的区别:false和extended:true已在此答案中解释。


分享到: