问题
I have two rails apps. The first app constantly calculates some data and stores it in Redis (This app is running on JRuby 1.7.4 and Rails 4). The second app reads this data from the same Redis server (This app is running on Ruby 2.0.0 and Rails 4). After trying to achieve this configuration in my local development environment, it's apparent that my Redis data is not being shared between the two apps. In both apps, my config/initializers/redis.rb file looks like this:
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/")
$redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
When I open up a rails console in either app, the Redis client looks like this (same database, same uri, same path, etc):
#<Redis client v3.0.4 for redis://localhost:6379/0>
But when I try to set a key/value in one app, the same key is not found in the other app. I feel like I'm missing something simple here.
SOLVED: I was using the fake-redis gem in development for one of my apps. This is why Redis appeared to be working in both apps but not sharing the data. Thanks for the help.
来源:https://stackoverflow.com/questions/18939394/get-two-rails-apps-to-share-the-same-redis-data