且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Redis 缓存 vs 直接使用内存

更新时间:2023-11-28 11:16:10

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.