在Node.js中保持setTimeout和setInterval重新启动 [英] Persist setTimeout and setInterval across Node.js restarts
问题描述
我为每个连接的用户设置了很多服务器端超时,其中setTimeout和setInterval可以持续10-30秒。如果Node.js实例在其中一个超时中间重新启动,则显然它们在重新启动时都被清除,这可能会导致这些用户出现一些问题。我如何坚持这些超时,或者是否有任何模块已经帮助了这个?
I set quite a few server-side timeouts with setTimeout and setInterval for each connected user that can last for 10-30 seconds. If the Node.js instance restarts in the middle of one of these timeouts, they are obviously all cleared on restart, which can cause some issues for these users. How would I go about persisting these timeouts, or are there any modules that already help with this?
推荐答案
我会存储开始Redis中的时间和持续时间,并在应用程序重新加载时重新启动不完整的计时器。一些Redis模块:
I would store the start times and durations in Redis and restart incomplete timers when your application reloads. Some Redis modules:
https://github.com/joyent/node/wiki/modules#wiki-db-nosql-redis
这篇关于在Node.js中保持setTimeout和setInterval重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!