mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #1464 from GarantiaData/single_redis_db
Support single redis DB.
This commit is contained in:
commit
7b7d6f3fa7
2 changed files with 58 additions and 3 deletions
|
@ -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.", ''
|
puts "Check your redis.yml and make sure it has configuration for the environment you're trying to use.", ''
|
||||||
raise 'Redis config not found'
|
raise 'Redis config not found'
|
||||||
end
|
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']}"
|
ActiveSupport::Cache::RedisStore.new host:redis_config['host'], port:redis_config['port'], password:redis_config['password'], db:redis_config['db'], namespace:->{ DiscourseRedis.namespace + "_cache" }
|
||||||
redis_store.options[:namespace] = -> { DiscourseRedis.namespace }
|
|
||||||
redis_store
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
57
spec/components/redis_store_spec.rb
Normal file
57
spec/components/redis_store_spec.rb
Normal 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
|
Loading…
Reference in a new issue