如何使用nodejs和express向会话(redis)添加事件监听器?
我想在用户会话被破坏/超时时运行一个函数。有没有办法使用 redis 会话存储在 Nodejs 中与 Express 一起使用?
I would like to run a function whenever a user's session is destroyed/times out. Is there a way to do with in nodejs with express using a redis session store?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
会话存储本身继承自 EventEmitter:
https://github .com/senchalabs/connect/blob/master/lib/middleware/session/store.js
尽管没有一个实现会发出事件供您绑定,包括 redis 存储:
https://github.com/visionmedia/connect-redis/blob /master/lib/connect-redis.js
你可以很容易地分叉 connect-redis 并自己破解这些事件,这样你就可以在需要的地方绑定到它们......
变成
然后你可以绑定到“破坏”事件...
The session store's themselves inherit from EventEmitter:
https://github.com/senchalabs/connect/blob/master/lib/middleware/session/store.js
Although none of the implementations emit events for you to bind to, including the redis store:
https://github.com/visionmedia/connect-redis/blob/master/lib/connect-redis.js
You could quite easily fork connect-redis and hack these events in yourself so that you may bind to them where you need to....
becomes
Then you may bind to the "destroy" event...