Is Redis faster than MySQL?
Asked Answered
C

3

18

I just read that Redis is "persistent". 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? Obviously, I am just a beginner, so don't be too harsh.

Connected to: Cheapest way to cache data in node.js?

Cleanlimbed answered 28/7, 2014 at 6:47 Comment(0)
H
21

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.

The persistence of Redis is optional. 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). 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 :

  • if you want reliable relational storage, you use MySQL (or another 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
Hydrography answered 28/7, 2014 at 6:54 Comment(4)
+1 for emphasizing that they solve a different problem and address a different use case. In my humble experience Redis is much faster for things that involve caching.Prefiguration
Would it be worth it to use Redis in this situation? my previous questionCleanlimbed
@Cleanlimbed Hard to tell. Without information it might be a good idea. But if you don't have enough memory, Redis won't be efficient.Piwowar
When you think about it, the majority of sql transactions are key-value pairs. i.e. "select * from table where id = X" is a key; the row is a value.Aphasia
T
7

The accepted answer only answer pros and cons, not answer Is Redis faster than MySQL?

The answer: Yes, Redis is faster than MySQL

How can it be faster: without cache, it depend on hardrive bandwidth (not query)

  • MySQL, use disk: 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

so if using MySQL with HDD 100 MB/s 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.

Tetrabrach answered 23/7, 2022 at 6:23 Comment(1)
Even if it is very old question, I think this answer should be selected as it is more relevant.Rivkarivkah
C
0

Redis is an in-memory but persistent on disk database

It stores data in memory first then constantly copys the data to disk.

Carmody answered 28/7, 2014 at 6:53 Comment(2)
So is it faster than mysql or not?Stephenson
Yes, as memory is faster than hd/ssd (although some sql can be cached which can help, but no guaranteed).Jackijackie

© 2022 - 2024 — McMap. All rights reserved.