Ruby on Rails always pointing local redis Server

redis, redis-objects, ruby, ruby-on-rails

Solution

As per Question:

// LOCAL REDIS SERVER
Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
// REMOTE REDIS SERVER
#Redis.current = Redis.new(:host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>')

Model.rb

 DataMapper.setup(:default, {:adapter  => "redis"})

In above code, I am overloading Redis configuration in User model. In that case, I need to write remote configuration in model as well.

DataMapper.setup(:default, {:adapter  => "redis", :host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>'})

Problem

I am using Redis with my ruby on rails application, To map Ruby object with Redis using redis-objects, dm-core and dm-redis-adapter. Below are the code snipts Gemfile ``` gem 'redis-objects' gem "dm-core", "~> 1.2.1" gem "dm-redis-adapter" ``` /config/initializers/redis.rb ``` // LOCAL REDIS SERVER Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379) // REMOTE REDIS SERVER #Redis.current = Redis.new(:host => '<VM IP>', :port => <VM PORT>, :password => '<PASSWORD>') ``` Model.rb ``` DataMapper.setup(:default, {:adapter => "redis"}) class User include Redis::Objects include DataMapper::Resource include ActiveModel::Validations include ActiveModel::Conversion # datamapper fields, just used for .create property :id, Serial property :name, String property :email, String property :des, Text def id 1 end end User.finalize ``` It's working fine for local redis server. Why app always pointing local redis, Even when providing remote host and port? SOLVED: checkout my answer.

Original source