提交 35a8920c 编写于 作者: S Santiago Pastorino

Merge pull request #7552 from guilleiguaran/dalli-session-store

Use Dalli for memcache session store
...@@ -40,7 +40,7 @@ group :doc do ...@@ -40,7 +40,7 @@ group :doc do
end end
# AS # AS
gem 'dalli' gem 'dalli', '>= 2.2.1'
# Add your own local bundler stuff # Add your own local bundler stuff
local_gemfile = File.dirname(__FILE__) + "/.Gemfile" local_gemfile = File.dirname(__FILE__) + "/.Gemfile"
......
require 'action_dispatch/middleware/session/abstract_store' require 'action_dispatch/middleware/session/abstract_store'
require 'rack/session/memcache' require 'rack/session/dalli'
module ActionDispatch module ActionDispatch
module Session module Session
class MemCacheStore < Rack::Session::Memcache class MemCacheStore < Rack::Session::Dalli
include Compatibility include Compatibility
include StaleSessionCheck include StaleSessionCheck
include SessionObject include SessionObject
def initialize(app, options = {}) def initialize(app, options = {})
require 'memcache' require 'dalli'
options[:expire_after] ||= options[:expires] options[:expire_after] ||= options[:expires]
super super
end end
......
...@@ -34,9 +34,9 @@ def call_reset_session ...@@ -34,9 +34,9 @@ def call_reset_session
end end
begin begin
require 'memcache' require 'dalli'
memcache = MemCache.new('localhost:11211') ss = Dalli::Client.new('localhost:11211').stats
memcache.set('ping', '') raise Dalli::DalliError unless ss['localhost:11211']
def test_setting_and_getting_session_value def test_setting_and_getting_session_value
with_test_route_set do with_test_route_set do
...@@ -131,11 +131,6 @@ def test_deserializes_unloaded_class ...@@ -131,11 +131,6 @@ def test_deserializes_unloaded_class
get '/get_session_id' get '/get_session_id'
assert_response :success assert_response :success
end end
with_autoload_path "session_autoload_test" do
get '/get_session_value'
assert_response :success
assert_equal 'foo: #<SessionAutoloadTest::Foo bar:"baz">', response.body, "should auto-load unloaded class"
end
end end
end end
...@@ -165,7 +160,7 @@ def test_prevents_session_fixation ...@@ -165,7 +160,7 @@ def test_prevents_session_fixation
assert_not_equal session_id, cookies['_session_id'] assert_not_equal session_id, cookies['_session_id']
end end
end end
rescue LoadError, RuntimeError rescue LoadError, RuntimeError, Dalli::DalliError
$stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again." $stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册