简体   繁体   English

Redis 比 MySQL 快吗?

[英]Is Redis faster than MySQL?

I just read that Redis is "persistent".我刚刚读到 Redis 是“持久的”。 Does that mean that it is stored in the hard disk?这是否意味着它存储在硬盘中? If yes, how can it be faster than MySQL, which is also hard disk based?如果是,它怎么能比同样基于硬盘的 MySQL 更快? Obviously, I am just a beginner, so don't be too harsh.显然,我只是一个初学者,所以不要太苛刻。

Connected to: Cheapest way to cache data in node.js?连接到: 在 node.js 中缓存数据的最便宜方法?

Redis only works on key value pairs, which is much simpler but is far from covering the normal use cases of a relational database like MySQL. Redis只适用于键值对,这更简单,但远不能涵盖像MySQL这样的关系数据库的正常用例。

The persistence of Redis is optional. Redis的持久性是可选的。 Many use cases don't need durability (for example I use Redis to store user sessions outside of my server program so that I can restart it without the users noticing). 许多用例不需要持久性(例如,我使用Redis在我的服务器程序之外存储用户会话,以便我可以重新启动它而无需用户注意)。 In that case there's no write on disk. 在那种情况下,磁盘上没有写入。

Even when you configure it for persistence, the writing isn't made at each write in the store which means you could lose up to a few seconds of data in a case of a severe crash. 即使您将其配置为持久性,也不会在存储中的每次写入时进行写入,这意味着在严重崩溃的情况下您可能会丢失多达几秒的数据。 But which also means much better performances. 但这也意味着更好的表现。

Overall, you don't really compare Redis and MySQL : 总的来说,你并不真正比较Redis和MySQL:

  • if you want reliable relational storage, you use MySQL (or another DBMS) 如果你想要可靠的关系存储,你使用MySQL(或其他DBMS)
  • if you can afford to lose a few seconds of data in case of crash and you only need to fast store and retrieve key-value pairs, then Redis might be interesting 如果您在崩溃的情况下能够丢失几秒钟的数据并且您只需要快速存储和检索键值对,那么Redis可能会很有趣

Redis is an in-memory but persistent on disk database Redis是一个内存但持久的磁盘数据库

It stores data in memory first then constantly copys the data to disk. 它首先将数据存储在内存中,然后不断将数据复制到磁盘。

The accepted answer only answer pros and cons, not answer Is Redis faster than MySQL?接受的答案只回答利弊,不回答Is Redis faster than MySQL?

The answer: Yes, Redis is faster than MySQL The answer: ,Redis 比 MySQL 快

How can it be faster: without cache, it depend on hardrive bandwidth (not query) How can it be faster:没有缓存,它取决于硬盘带宽(不是查询)

  • MySQL, use disk: HDD 100 MB/s, SSD 500 MB/s, NVME 500-3000 MB/s MySQL,使用磁盘:HDD 100 MB/s,SSD 500 MB/s,NVME 500-3000 MB/s

  • Redis, other noSQL, use Memory/RAM: DDR3 15,000 MB/s, DDR4 25,600 MB/s Redis,其他 noSQL,使用内存/RAM:DDR3 15,000 MB/s,DDR4 25,600 MB/s

so if using MySQL with HDD 100 MB/s VS Redis DDR4 25,600 MB/s = 256X faster*因此,如果使用带有 HDD 100 MB/s 的 MySQL VS Redis DDR4 25,600 MB/s = 256X faster*

*note: not real performance, only theoretically *注:非实际性能,仅理论上

which is also hard disk based? both using hard disk but Redis only use HDD for backup/restore.两者都使用硬盘,但 Redis 仅使用 HDD 进行备份/恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM