Use two different databases in one project

混江龙づ霸主 提交于 2020-01-14 01:41:07

问题


Is it possible to use two different databases for the same project in Ruby On Rails?

At the moment I use PostgreSQL with Heroku for my project and I would like to use Redis to store some of my models.

Thanks


First step, add redis-rb to your Gemfile:

gem 'redis', '2.1.1'

Then install the gem via Bundler:

bundle install

Lastly, create an initializer in config/initializers/redis.rb and add the following:

$redis = Redis.new(:host => 'localhost', :port => 6379)

Will that have any side effects to my existing database PostgreSQL database?

Or I 'll able to use $redis whenever I want to store something?


回答1:


If you follow the steps you've written, you shouldn't have any problems with ActiveRecord/Postgres

$redis will work fine for you, as long as the connection works.




回答2:


If you want to use Redis as a database storage for your model then you should use some of the available gems that lets you easily store objects in Redis. Some of the gems are:

  • OHM
  • Redis::Objects


来源:https://stackoverflow.com/questions/6808645/use-two-different-databases-in-one-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!