2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-09-24 08:47:35 -04:00
|
|
|
require 'cache'
|
|
|
|
|
|
|
|
describe "Redis Store" do
|
|
|
|
|
|
|
|
let :cache do
|
2014-01-06 00:50:04 -05:00
|
|
|
Cache.new(namespace: 'foo')
|
2013-09-24 08:47:35 -04:00
|
|
|
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"
|
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(r).to eq("key in store")
|
2013-09-24 08:47:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't collide with our Cache" do
|
2014-01-06 00:50:04 -05:00
|
|
|
|
2013-09-24 08:47:35 -04:00
|
|
|
store.fetch "key" do
|
|
|
|
"key in store"
|
|
|
|
end
|
2014-01-06 00:50:04 -05:00
|
|
|
|
2013-09-24 08:47:35 -04:00
|
|
|
cache.fetch "key" do
|
|
|
|
"key in cache"
|
|
|
|
end
|
2014-01-06 00:50:04 -05:00
|
|
|
|
2013-09-24 08:47:35 -04:00
|
|
|
r = store.read "key"
|
2014-01-06 00:50:04 -05:00
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(r).to eq("key in store")
|
2013-09-24 08:47:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can be cleared without clearing our cache" do
|
2019-11-27 00:11:49 -05:00
|
|
|
cache.clear
|
|
|
|
store.clear
|
|
|
|
|
2013-09-24 08:47:35 -04:00
|
|
|
store.fetch "key" do
|
|
|
|
"key in store"
|
|
|
|
end
|
|
|
|
|
|
|
|
cache.fetch "key" do
|
|
|
|
"key in cache"
|
|
|
|
end
|
|
|
|
|
|
|
|
store.clear
|
2019-11-27 00:11:49 -05:00
|
|
|
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(store.read("key")).to eq(nil)
|
|
|
|
expect(cache.fetch("key")).to eq("key in cache")
|
2014-01-06 00:50:04 -05:00
|
|
|
|
2013-09-24 08:47:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|