Redis缓存与直接使用内存 [英] Redis cache vs using memory directly

查看:499
本文介绍了Redis缓存与直接使用内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有使用过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缓存与直接使用内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆