Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis as a database

Tags:

redis

I want to use Redis as a database, not a cache. From my (limited) understanding, Redis is an in-memory datastore. What are the risks of using Redis, and how can I mitigate them?

like image 482
Paddy Avatar asked Jan 17 '11 23:01

Paddy


People also ask

Can I use Redis as persistent database?

No persistence: Redis can be entirely ephemeral with no persistence at all. Our data is only available while the server is running, and if for some reason the server was terminated or rebooted our data is lost.

Why Redis is not used as database?

As Redis is an in-memory storage, you cannot store large data that won't fit you machine's memory size. Redis usually work very bad when the data it stores is larger than 1/3 of the RAM size. So, this is the fatal limitation of using Redis as a database.


2 Answers

You can use Redis as an authoritative store in a number of different ways:

  • Turn on AOF (Append-only File store) see AOF docs. This will keep a log of all Redis commands made against your dataset in real-time.

  • Run Redis using Master-Slave replication see replication docs. This will allow you to provide high-availability if one of your instances fails.

  • If you're running on something like EC2 you can EBS back your Redis partition to provide another layer of protection against instance failure.

On the horizon is Redis Cluster - this is specifically designed as a way to run Redis in a way that should help with HA and scalability. However, this won't appear for at least another six months or so.

like image 177
rlotun Avatar answered Sep 21 '22 13:09

rlotun


Redis is an in-memory store which can also write the data back to disc. You can specify how many times to do a fsync to make redis safer(but also slower => trade-off) .

But still I am not certain if redis is in state yet to really store (mission) critical data in it (yet?). If for example it is not a huge problem when 1 more tweets(twitter.com) or something similiar get losts then I would certainly use redis. There is also a lot of information available about persistence at redis's own website.

You should also be aware of some persistence problems which could occur by reading antirez(redis maintainers) blog article. You should read his blog because he has some interesting articles.


like image 26
Alfred Avatar answered Sep 19 '22 13:09

Alfred