Merge pull request #1464 from GarantiaData/single_redis_db

Support single redis DB.
This commit is contained in:
Sam 2014-01-05 16:30:41 -08:00
commit 7b7d6f3fa7
2 changed files with 58 additions and 3 deletions

View File

@ -69,9 +69,7 @@ class DiscourseRedis
puts "Check your redis.yml and make sure it has configuration for the environment you're trying to use.", ''
raise 'Redis config not found'
end
redis_store = ActiveSupport::Cache::RedisStore.new "redis://#{(':' + redis_config['password'] + '@') if redis_config['password']}#{redis_config['host']}:#{redis_config['port']}/#{redis_config['cache_db']}"
redis_store.options[:namespace] = -> { DiscourseRedis.namespace }
redis_store
ActiveSupport::Cache::RedisStore.new host:redis_config['host'], port:redis_config['port'], password:redis_config['password'], db:redis_config['db'], namespace:->{ DiscourseRedis.namespace + "_cache" }
end

View File

@ -0,0 +1,57 @@
require 'spec_helper'
require 'cache'
describe "Redis Store" do
let :cache do
Cache.new
end
let :store do
DiscourseRedis.new_redis_store
end
before(:each) do
cache.redis.del "key"
store.delete "key"
end
it "can store stuff" do
store.fetch "key" do
"key in store"
end
r = store.read "key"
r.should == "key in store"
end
it "doesn't collide with our Cache" do
store.fetch "key" do
"key in store"
end
cache.fetch "key" do
"key in cache"
end
r = store.read "key"
r.should == "key in store"
end
it "can be cleared without clearing our cache" do
store.fetch "key" do
"key in store"
end
cache.fetch "key" do
"key in cache"
end
store.clear
store.read("key").should be_nil
cache.fetch("key").should == "key in cache"
end
end