Use Redis as primary database in Rails app
Asked Answered
O

3

7

Hello I am newbie to Redis. I am trying to use Redis as my primary database instead of sqlite as provided by default with Rails. I tried enough googling but could not find relevant stuff. How to achieve this? Or if iam wrong whether can we use Redis as primary database in Rails application?

Thanks

Ozonosphere answered 19/4, 2017 at 5:11 Comment(1)
go through muut.com/blog/technology/redis-as-primary-datastore-wtf.htmlSempiternal
T
3

Typically you'd use a library like https://github.com/nateware/redis-objects. As its README says, it's not just another way to store ActiveRecords, since you may as well keep it simple and use MySQL or Postgres if all you want is ActiveRecords. Instead, redis-object will let you use Redis data structures as they are intended to be used.

This is not an ORM. People that are wrapping ORM’s around Redis are missing the point.

The killer feature of Redis is that it allows you to perform atomic operations on individual data structures, like counters, lists, and sets. The atomic part is HUGE. Using an ORM wrapper that retrieves a "record", updates values, then sends those values back, removes the atomicity, cutting the nuts off the major advantage of Redis. Just use MySQL, k?

You can also just install the Redis gem and make your own calls to Redis, but that kind of low-level programming would largely defeat the purpose of using a powerful framework like Rails.

Tetratomic answered 19/4, 2017 at 5:40 Comment(0)
D
0

It is possible to configure Redis persistence RDB + AOF and with that option you can use only Redis, but be aware that having RDB + AOF will be impacting Redis performance for write operations and there might be another issues mapping you in-memory data to disk and vice versa.

Redis is in-memory storage and, as you already know, there are some hurdles making it primary database. Also you can try ready-to-go solutions like AWS MemoryDB, which is reliable database and Redis at the same time. If you can't use solutions like that, I don't recommend focusing effort try store data only on Redis and have data backed up by regular, well understood database.

Daredevil answered 11/2 at 8:2 Comment(0)
O
-5

Got it. Redis can't be used as primary database as it is in-memory key-value store. What if something happens to the memory? Data is not persisted.

Ozonosphere answered 1/6, 2017 at 5:10 Comment(2)
This answer is not actually true.By default Redis saves snapshots of the dataset on disk, in a binary file called dump.rdb. You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset, or you can manually call the SAVE or BGSAVE commands.source linkHobnailed
Thanks @HobnailedOzonosphere

© 2022 - 2024 — McMap. All rights reserved.