在一个项目中使用两个不同的数据库 [英] Use two different databases in one project
问题描述
是否可以在 Ruby On Rails 中为同一个项目使用两个不同的数据库?
Is it possible to use two different databases for the same project in Ruby On Rails?
目前我在我的项目中使用 PostgreSQL 和 Heroku,我想使用 Redis 来存储我的一些模型.
At the moment I use PostgreSQL with Heroku for my project and I would like to use Redis to store some of my models.
谢谢
第一步,将 redis-rb 添加到您的 Gemfile:
First step, add redis-rb to your Gemfile:
gem 'redis', '2.1.1'
然后通过 Bundler 安装 gem:
Then install the gem via Bundler:
bundle install
最后,在 config/initializers/redis.rb 中创建一个初始化程序并添加以下内容:
Lastly, create an initializer in config/initializers/redis.rb and add the following:
$redis = Redis.new(:host => 'localhost', :port => 6379)
这会对我现有的数据库 PostgreSQL 数据库产生任何副作用吗?
Will that have any side effects to my existing database PostgreSQL database?
或者我可以在想要存储一些东西时使用 $redis ?
Or I 'll able to use $redis whenever I want to store something?
推荐答案
如果你按照你写的步骤操作,ActiveRecord/Postgres 应该不会有任何问题
If you follow the steps you've written, you shouldn't have any problems with ActiveRecord/Postgres
$redis
就可以正常工作.
这篇关于在一个项目中使用两个不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!