I wanted to use Redis as the cache store for a Rails 2.3.8 app. After a little shopping around, I settled on RedisStore as the cache adapter. I following the configuration directions on the RedisStore website and restarted the app, expecting everything to be hunky-dory. Instead, I was kicked in the face with this:
uninitialized constant ActiveSupport::Cache::RedisStore
My redis-store configuration looked like this:
redis_config = YAML.load_file(RAILS_ROOT + '/config/redis.yml')[RAILS_ENV] config.cache_store = :redis_store, redis_config
I took another look at the config instructions and realized I was using the Rails 3.x setup. Following the 2.x instructions, I updated the configuration to look like this:
redis_config = YAML.load_file(RAILS_ROOT + '/config/redis.yml')[RAILS_ENV] config.gem 'redis-store' config.cache_store = :redis_store, redis_config
After restarting the app, I was still seeing the same
uninitialized constant error. Finally, a bit more googling revealed that v1.1.0 of redis-store didn't jive with Rails 2.3.8. Evidently what I needed was v22.214.171.124. I'm not sure why it's v126.96.36.199 and not v1.0.1, but I checked rubygems.org and saw that v1.0.0 was yanked for some reason.
Anyway, so I updated my Gemfile to specify version v188.8.131.52 of redis-store and bam! The app starts up without yelling at me. Good stuff. Or so I thought.
Everything was hunky-dory in my local development environment, but when I started testing in our staging environment, something was up. Our staging environment consists of two app servers, one of which has the Redis instance running on it.
Attempts to connect to Redis repeated failed with an "unable to connect" error on one web server, but not the other. Examining the redis connection, it was clear that the app was trying to access Redis via localhost, the default when no valid connection options were supplied. This explained why it worked on one app server and not the other, since Redis was in fact running locally on one of them.
A little console debugging demonstrated that the redis config expected a hash with symbol keys, whereas the config hash loaded from the yaml file had string keys.
config.cache_store = :redis_store, redis_config.symbolize_keys
Updating the redis-store config to symbolize the keys allowed the connection to be properly created, and everything was working as intended.