Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean for Redis to be an "in memory" database?

Tags:

redis

Wikipedia says that Redis is an in-memory database, but it also says that it can persist "data to the disk at least every 2 seconds". I feel like these two things are mutually exclusive. How can it be considered in-memory yet (it can) store data on disk? I assumed the definition of in-memory meant that it does not store to disk.


This is a similar question: Redis concept: In memory or DB? The difference is that he's asking about the persistence implementation. My question is about the concept of in-memory vs persistence.

like image 300
Daniel Kaplan Avatar asked Feb 25 '15 02:02

Daniel Kaplan


People also ask

What is meant by in-memory database?

In-memory databases are purpose-built databases that rely primarily on memory for data storage, in contrast to databases that store data on disk or SSDs. In-memory data stores are designed to enable minimal response times by eliminating the need to access disks.

How does Redis store in-memory?

Redis is an In-Memory Database(IMDB) as it relies on main memory of computer for data storage while others use Disk Storage database mechanism. That is why Redis is faster than disk-optimized databases because disk access is slower than memory access.

Is Redis persistent or in-memory?

Data size is predictable and limited: Redis data is always kept in memory, even when backup to disk, and RAM is much more expensive than Hard drive (the cost of a 500GB RAM cluster in any Cloud provide environment will convince you of that).

Is Redis in-memory or distributed cache?

Redis is an open source in-memory data store, which is often used as a distributed cache. You can configure an Azure Redis Cache for an Azure-hosted ASP.NET Core app, and use an Azure Redis Cache for local development.


1 Answers

Redis is an in-memory but persistent on disk database, so it represents a different trade off where very high write and read speed is achieved with the limitation of data sets that can't be larger than memory. Another advantage of in memory databases is that the memory representation of complex data structures is much simpler to manipulate compared to the same data structure on disk, so Redis can do a lot, with little internal complexity. At the same time the two on-disk storage formats (RDB and AOF) don't need to be suitable for random access, so they are compact and always generated in an append-only fashion (Even the AOF log rotation is an append-only operation, since the new version is generated from the copy of data in memory).

http://redis.io/topics/faq

In redis, all data has to be in memory. This is the point which is totally different from other NoSQL. Usually when you access and read some data in a database, you don't know if the data is in memory (cache) or not, but in the case of Redis, it's guaranteed that all data is in memory. Writing to disk is optional, which you can think of as having the trunk on memory and a kind of backup on the disk. You may lose data which is saved after last saving to a disk if you suddenly turn off the server.

And of course the advantage of it is a performance. Since all data is in RAM, it's incredibly fast.

like image 126
suish Avatar answered Oct 27 '22 18:10

suish