Tebe
Tebe

Reputation: 3214

Why do we have Redis when we have MySQL temporary tables?

MySQL temporary table are stored in memory as long as computer has enough RAM (and MySQL was set up accordingly). One can created any indexes for any fields.

Redis stores data in memory indexed by one key at time and in my understanding MySQL can do this job too.

Are there any things that make Redis better for storing big amount(100-200k rows) of volatile data? I can only explain the appearance of Redis that not every project has mysql inside and probably some other databases don't support temporary tables.

If I already have MySql in my project, does it make sense to put up with Redis?

Upvotes: 4

Views: 2667

Answers (2)

Itamar Haber
Itamar Haber

Reputation: 50102

By using Redis alongside the other database, you're effectively reducing the load on it. Also, when Redis is running on a different server, scaling can be performed independently on each tier.

Upvotes: 2

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

Redis is like working with indexes directly. There's no ACID, SQL parser and many other things between you and the data.

It provides some basic data structures and they're specifically optimized to be held in memory, and they also have specific operations to read and modify them.

In the other hand, Redis isn't designed to query data (but you can implement very powerful and high-performant filters with SORT, SCAN, intersections and other operations) but to store the data as you're going to be consumed later. If you want to get, for example, customers sorted by 3 different criterias, you'll need to work to fill 3 different sorted sets. There're a lot of use cases with other data structures, but I would end up writing a book in an answer...

Also, one of most powerful features found in Redis is how easy can be replicated, and since its 3.0 version, it supports data sharding out-of-the-box.

About why you would need to use Redis instead of temporary tables on MySQL (and other engines which have them too) is up to you. You need to study your case and check if caching or storing data in a NoSQL storage like Redis can both outperform your actual approach and it provides you a more elegant data architecture.

Upvotes: 7

Related Questions