Redis 缓存 vs 直接使用内存 [英] Redis cache vs using memory directly
问题描述
我还没有使用过 Redis,但我听说过它并打算尝试将其用作缓存存储.
I have not used Redis yet, but I heard about it and plan to try it as cache storing.
听说 Redis 使用内存作为缓存存储数据库,那么如果我使用变量作为对象或字典数据类型来存储数据有什么区别?喜欢:
I heard Redis using memory as cache store database, so what's the difference if I use a variable as an object or dictionary datatype to store data? like:
var cache = {
key: {
},
key: {
}
...
}
Redis 有什么优势?
What's the advantage Redis have?
推荐答案
Redis 是一个远程数据结构服务器.它肯定比仅将数据存储在本地内存中要慢(因为它涉及套接字往返来获取/存储数据).然而,它也带来了一些有趣的特性:
Redis is a remote data structure server. It is certainly slower than just storing the data in local memory (since it involves socket roundtrips to fetch/store the data). However, it also brings some interesting properties:
Redis 可以被您的应用程序的所有进程访问,可能在多个节点上运行(本地内存无法实现).
Redis can be accessed by all the processes of your applications, possibly running on several nodes (something local memory cannot achieve).
Redis 内存存储非常高效,并且在单独的进程中完成.如果应用程序运行在内存被垃圾回收的平台(node.js、java 等)上,它允许处理更大的内存缓存/存储.在实践中,非常大的堆在垃圾收集语言中表现不佳.
Redis memory storage is quite efficient, and done in a separate process. If the application runs on a platform whose memory is garbage collected (node.js, java, etc ...), it allows handling a much bigger memory cache/store. In practice, very large heaps do not perform well with garbage collected languages.
Redis 可以根据需要将数据保存在磁盘上.
Redis can persist the data on disk if needed.
Redis 不仅仅是一个简单的缓存:它提供了各种数据结构、各种项目驱逐策略、阻塞队列、发布/订阅、原子性、Lua 脚本等......
Redis is a bit more than a simple cache: it provides various data structures, various item eviction policies, blocking queues, pub/sub, atomicity, Lua scripting, etc ...
Redis 可以通过主/从机制复制其活动,以实现高可用性.
Redis can replicate its activity with a master/slave mechanism in order to implement high-availability.
基本上,如果您需要应用程序在共享相同数据的多个节点上进行扩展,那么将需要诸如 Redis(或任何其他远程键/值存储)之类的东西.
Basically, if you need your application to scale on several nodes sharing the same data, then something like Redis (or any other remote key/value store) will be required.
这篇关于Redis 缓存 vs 直接使用内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!