Class: Rack::Session::Riak
- Inherits:
-
Abstract::ID
- Object
- Abstract::ID
- Rack::Session::Riak
- Defined in:
- lib/riak_sessions.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
Abstract::ID::DEFAULT_OPTIONS.merge( :drop => false, :riak_server => '127.0.0.1', :riak_port => 8098 )
Instance Attribute Summary collapse
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
- #get_session(env, sid) ⇒ Object
-
#initialize(app, options = {}) ⇒ Riak
constructor
A new instance of Riak.
- #set_session(env, session_id, new_session, options) ⇒ Object
Constructor Details
Instance Attribute Details
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
52 53 54 |
# File 'lib/riak_sessions.rb', line 52 def mutex @mutex end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
52 53 54 |
# File 'lib/riak_sessions.rb', line 52 def pool @pool end |
Instance Method Details
#get_session(env, sid) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/riak_sessions.rb', line 67 def get_session(env, sid) session = @pool[sid] if sid @mutex.lock if env['rack.multithread'] unless sid and session env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil? session = {} sid = generate_sid @pool.store sid, session end return [sid, session] ensure @mutex.unlock if env['rack.multithread'] end |
#set_session(env, session_id, new_session, options) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/riak_sessions.rb', line 83 def set_session(env, session_id, new_session, ) @mutex.lock if env['rack.multithread'] if [:renew] or [:drop] @pool.delete session_id return false if [:drop] session_id = generate_sid @pool.store session_id, 0 end @pool.store session_id, new_session return session_id rescue warn "#{new_session.inspect} has been lost." warn $!.inspect ensure @mutex.unlock if env['rack.multithread'] end |