NEST JS从内存商店获取会话数据
我想知道是否有一种方法可以直接访问Session Memory Store,并获取我使用Express-Session软件包的特定会话ID的会话数据。
I was wondering if there is a method to access directly the session memory store and get the session data for a particular session id i'm using express-session package with the nest js freamwork.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望您从那以后找到了问题的答案。我想到了使用Nestjs DI系统的以下技术。
背景
内注册一个会话中间软件main.ts
文件。所有会话存储都共享一个共同的接口,因此它是应用程序的可互换部分,这使得它们可以由模块作为注射令牌提供。请参阅 list> list express express商店的session商店。
实现详细信息
创建一个新的模块(例如SessionModule),然后将其添加到AppModule中的导入数组中。
接下来,我们为会话商店创建注射令牌。
where
session.const.ts
现在在main.ts
文件中包含一个简单的导出语句,您可以获取对Session Store的引用到SETUP SESICS MIDDERWARE。
如果要在其他服务 /控制器中访问SessionStore,则必须将SessionModule导入声明它们的模块。
前任。
借助SessionStore属性,您可以获取任何存储的会话,其中包含链接的ExpressJS文档中记录的以下方法。
store.get(SID,回调)
Hope you found answers to your question since then. I came up with the following technique which is using NestJS DI system.
Background
main.ts
file.session(options)
on top of the page), you can specify the session store that will be used by the middleware. If its omitted then the default MemoryStore is used.All the session stores shares a common interface, so its a interchangeable part of your application, which makes a good candidate them to be provided as an injection token by a module. See a list of session stores advised by expressjs.
Implementation details
Create a new module (e.g. SessionModule), then add it to the imports array in your AppModule.
Next we create the injection token for the session store.
where
session.const.ts
contains a simple export statementNow inside
main.ts
file, you can get a reference to the session store to setup session middleware.If you want to access sessionStore in other services / controllers you have to import the SessionModule to the module that declares them.
ex.
With the sessionStore property you can get any stored session with the following method documented in the linked expressjs documentation.
store.get(sid, callback)