Sha256: 42fea05186596a67035d227636bb4b368897c1b8f1d69dc540bd520e9855e27c
Contents?: true
Size: 1.61 KB
Versions: 23
Compression:
Stored size: 1.61 KB
Contents
# Copyright © 2012 The Pennsylvania State University # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. if defined?(PhusionPassenger) PhusionPassenger.on_event(:starting_worker_process) do |forked| # We're in smart spawning mode. if forked # Re-establish redis connection require 'redis' config = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'redis.yml'))).result)[Rails.env].with_indifferent_access # The important two lines $redis.client.disconnect if $redis $redis = Redis.new(host: config[:host], port: config[:port], thread_safe: true) rescue nil Resque.redis.client.reconnect if Resque.redis end end else config = YAML::load(ERB.new(IO.read(File.join(Rails.root, 'config', 'redis.yml'))).result)[Rails.env].with_indifferent_access $redis = Redis.new(host: config[:host], port: config[:port], thread_safe: true) rescue nil end # Code borrowed from Obie's Redis patterns talk at RailsConf'12 Nest.class_eval do def initialize(key, redis=$redis) super(key.to_param) @redis = redis end def [](key) self.class.new("#{self}:#{key.to_param}", @redis) end end
Version data entries
23 entries across 23 versions & 2 rubygems