glarkou
glarkou

Reputation: 7101

Use two different databases in one project

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?

Upvotes: 2

Views: 351

Answers (2)

Thiago Jackiw
Thiago Jackiw

Reputation: 799

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:

Upvotes: 0

Dogbert
Dogbert

Reputation: 222398

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.

Upvotes: 1

Related Questions