From 0c8f6ba9a4deb2370a053eeb754a43add0cabb11 Mon Sep 17 00:00:00 2001 From: Discourse application Date: Tue, 24 Sep 2013 15:47:35 +0300 Subject: [PATCH] Support single redis DB. --- lib/discourse_redis.rb | 4 +- spec/components/redis_store_spec.rb | 57 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 spec/components/redis_store_spec.rb diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index d439d4aab..21a0f1f32 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -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 diff --git a/spec/components/redis_store_spec.rb b/spec/components/redis_store_spec.rb new file mode 100644 index 000000000..b7d0746f7 --- /dev/null +++ b/spec/components/redis_store_spec.rb @@ -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