Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Redis as primary database in Rails app

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

like image 503
Aashish Avatar asked Nov 27 '22 02:11

Aashish


1 Answers

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.

like image 186
mahemoff Avatar answered Dec 04 '22 01:12

mahemoff