0

I am using Redis Objects with Redis To Go on Heroku. I have a counter on a model, like this:

class Performance < ActiveRecord::Base
 include Redis::Objects

 counter :tickets_sold, start: 0
end

Accessing this value from Heroku console is working great as well.

irb(main):002:0> Performance.last.tickets_sold.value
 Performance Load (3.9ms)  SELECT `performances`.* FROM `performances` ORDER BY `performances`.`id` DESC LIMIT 1
=> 0

I confirmed that Redis.current is present:

irb(main):003:0> Redis.current 
=> # Redis client v2.2.2 connected to redis://ray.redistogo.com:9023/0 (Redis v2.4.11)

However, accessing the same counter from a template on the website runs into a Errno::ECONNREFUSED error.

Connection refused - Unable to connect to Redis on 127.0.0.1:6379

Why is it trying to connect to the local Redis url? Inspecting Redis.current on the website is also failing with the connection error above. Considering that the same command is working just fine from the Heroku console, I'm a little puzzled as to what's going on here. I hope someone has seen this before and knows how to solve it...

picardo
  • 24,530
  • 33
  • 104
  • 151
  • You should establish the connection with `$redis = Redis.new(url: ENV["REDISTOGO_URL"])`. Not sure why it's doing this, but it works for me – neersighted Oct 08 '12 at 00:12
  • I figure it out. I am using Redis gem 2.2.2, and that version requires $redis, and I was using Redis.current, which seems to work for the later versions. – picardo Oct 08 '12 at 17:12

0 Answers0