admin管理员组文章数量:1208155
My Node server gathers data in the form of nested arrays, once every minute or so. The data looks like this [[8850, 3.1, '2009jckdsfj'], ..., [8849.99, 25.3, '8sdcach83']]
There are about 2000 of these arrays that need to be cached. Persistence isn't important since I'm updating it so often.
Using redis seems like the "thing to do," however I can't see the benefit. Using a javascript object, I wouldn't need to stringify and parse the arrays to store and consume them.
What advantages would redis offer in this situation?
My Node server gathers data in the form of nested arrays, once every minute or so. The data looks like this [[8850, 3.1, '2009jckdsfj'], ..., [8849.99, 25.3, '8sdcach83']]
There are about 2000 of these arrays that need to be cached. Persistence isn't important since I'm updating it so often.
Using redis seems like the "thing to do," however I can't see the benefit. Using a javascript object, I wouldn't need to stringify and parse the arrays to store and consume them.
What advantages would redis offer in this situation?
Share Improve this question asked May 14, 2018 at 0:37 icey-ticey-t 3033 silver badges11 bronze badges 1- Is there any mechanism in Node.js to persist data in local memory between subsequent requests? Something like shared-memory? – Tom Raganowicz Commented Jun 26, 2019 at 20:17
1 Answer
Reset to default 27Here are some reasons to use redis:
Multiple processes can access the data. It runs in a separate process and has a networked API so multiple processes can access the data. For example, if you were using clustering and wanted all clustered instances to have access to the same data, you would need to use some external database (such as Redis).
Memory usage separate from node.js. It runs in a separate process so its memory usage is separate from node.js. If you were storing a very large amount of data, it's possible that redis would handle that large memory usage better than node.js would or that you'd be better off with the usage split between two processes rather than all in node.js.
Redis offers features that aren't part of standard Javascript. These include pub/sub, data querying, transactions, expiring keys (ideal for data meant to expire such as sessions), LRU aging of keys (ideal for bounded caches), data structures not built into Javascript such as sorted sets, bitmaps, etc... to name only a few.
Redundancy/replication/high availability. If your data doesn't need to be long term on disk, but does need to be robust, you may want data protection against the failure of any single server. You can use data replication to multiple redis servers and thus have failover, backup without taking on the added performance drag of persisting to disk.
This said, there's no reason to use redis because it's the "thing to do". Use redis only if you identify a problem you have that it solves better than just using an object store inside of node.js.
FYI, the redis site offers a whole series of white papers on all sorts of things related to redis. Those whitepapers might be a good source of further info also.
本文标签: nodejsRedis vs Javascript objects What advantages does Redis offer in this caseStack Overflow
版权声明:本文标题:node.js - Redis vs Javascript objects. What advantages does Redis offer in this case? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738714823a2108414.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论