Support single redis DB.

This commit is contained in:
Discourse application 2013-09-24 15:47:35 +03:00
parent 07d08b81c7
commit 0c8f6ba9a4
2 changed files with 58 additions and 3 deletions

View File

@ -63,9 +63,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