Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

There should be a way to (easily) reconnect #21

Closed
xxx opened this Issue · 6 comments

3 participants

@xxx

Hi,

When deploying redis-store on Rails 2 with unicorn and preload_app in your unicorn config is true, the workers will share an outgoing socket to Redis, causing much pain.

The way around it is to get a new connection after the child has forked in the unicorn conf's after_fork hook, but right now I have to access the Redis object itself to do it:

Rails.cache.instance_variable_get(:@data).client.reconnect

Am I just missing something? I'm not sure of any other way to do this currently, but I think there should be.

thanks!

@xxx

For distributed stores, the method is a little different:
Rails.cache.instance_variable_get(:@data).instance_variable_get(:@ring).instance_variable_get(:@nodes).each do |node|
node.client.reconnect
end

@jodosha
Owner

Introducing Rails.cache.reconnect, useful for Unicorn environments. Closed by 3f0dcb3

@jodosha jodosha closed this
@jodosha
Owner

Now you can use Rails.cache.reconnect.

@nengxu nengxu referenced this issue from a commit in nengxu/redis-store
Luca Guidi Introducing Rails.cache.reconnect, useful for Unicorn environments. C…
…loses #21
3f0dcb3
@adamgotterer

Is Rails.cache.reconnect still the correct way to reconnect using Unicorn? I'm having an issue where the cache is trying to use localhost instead of the redistogo settings from the config. But adding the reconnect call didn't fix my issue.

after_fork do |server, worker|
  if defined?(Resque)
    if ENV["REDISTOGO_URL"]
      uri = URI.parse(ENV["REDISTOGO_URL"])
      Resque.redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
    end
    Rails.logger.info("Connected to Redis")
  end

  Rails.cache.reconnect
end    

Update: Because the connection keeps failing I'm actually ending up in an infinite crash cycle

@jodosha
Owner

@adamgotterer that Rails.cache.reconnect calls the Redis adapter for AS (redis-activesupport gem), which delegates to RS core (redis-store gem), which uses Redis client's (redis-rb gem) #reconnect https://github.com/redis-store/redis-store/blob/master/lib/redis/store.rb#L15.

Which version of the Redis gem are you using? Would you please try with a standalone connection and @redis.reconnect in the same environment and circumstance (after_fork)? Before to debug this, I want to be sure the problem belongs to RS. Thanks.

@adamgotterer

Everything is working now. The problem wasn't with the reconnect. I'm not positive but I think the problems stemmed from calling redis.quit. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.