Class: TokenRedisSessionStore::TokenRedisStore
- Inherits:
-
ActionDispatch::Session::AbstractStore
- Object
- ActionDispatch::Session::AbstractStore
- TokenRedisSessionStore::TokenRedisStore
- Defined in:
- lib/token_redis_session_store.rb
Overview
Token Redis session storage that uses redis and passes the sessionid on an http header instead of cookie
Instance Method Summary collapse
-
#delete_session(req, sid, _session) ⇒ Object
Remove a session from the cache.
-
#find_session(_req, sid) ⇒ Object
Get a session from the cache.
-
#initialize(app, options = {}) ⇒ TokenRedisStore
constructor
A new instance of TokenRedisStore.
-
#write_session(_req, sid, session, options) ⇒ Object
Set a session in the cache.
Constructor Details
#initialize(app, options = {}) ⇒ TokenRedisStore
Returns a new instance of TokenRedisStore.
8 9 10 11 12 13 14 |
# File 'lib/token_redis_session_store.rb', line 8 def initialize(app, = {}) = [:redis] || {} @session_header = [:session_header] || 'Session-Id' @redis = Redis.new() [:defer] = true super end |
Instance Method Details
#delete_session(req, sid, _session) ⇒ Object
Remove a session from the cache.
38 39 40 41 42 |
# File 'lib/token_redis_session_store.rb', line 38 def delete_session(req, sid, _session) req.delete_header "HTTP_#{@session_header.sub('-', '_').upcase}" redis.del(sid) generate_sid end |
#find_session(_req, sid) ⇒ Object
Get a session from the cache.
17 18 19 20 21 22 23 |
# File 'lib/token_redis_session_store.rb', line 17 def find_session(_req, sid) unless sid && (session = parse_session(sid)) sid = generate_sid session = {} end [sid, session] end |
#write_session(_req, sid, session, options) ⇒ Object
Set a session in the cache.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/token_redis_session_store.rb', line 26 def write_session(_req, sid, session, ) unless session.nil? if [:expire_after].nil? redis.set(sid, session.to_json) else redis.setex(sid, [:expire_after], session.to_json) end end sid end |