Class: RedisSessionStore
- Inherits:
-
ActionDispatch::Session::AbstractStore
- Object
- ActionDispatch::Session::AbstractStore
- RedisSessionStore
- Defined in:
- lib/redis-session-store.rb
Overview
Redis session storage for Rails, and for Rails only. Derived from the MemCacheStore code, simply dropping in Redis instead.
Defined Under Namespace
Classes: HybridSerializer, JsonSerializer
Constant Summary collapse
- VERSION =
'0.6.6'
- ENV_SESSION_OPTIONS_KEY =
Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
Instance Attribute Summary collapse
-
#on_redis_down ⇒ Object
Returns the value of attribute on_redis_down.
-
#on_session_load_error ⇒ Object
Returns the value of attribute on_session_load_error.
-
#on_sid_collision ⇒ Object
Returns the value of attribute on_sid_collision.
Instance Method Summary collapse
-
#initialize(app, options = {}) ⇒ RedisSessionStore
constructor
Options *
:key
- Same as with the other cookie stores, key name *:redis
- A hash with redis-specific options *:host
- Redis host name, default is localhost *:port
- Redis port, default is 6379 *:db
- Database number, defaults to 0.
Constructor Details
#initialize(app, options = {}) ⇒ RedisSessionStore
Options
-
:key
- Same as with the other cookie stores, key name -
:redis
- A hash with redis-specific options-
:host
- Redis host name, default is localhost -
:port
- Redis port, default is 6379 -
:db
- Database number, defaults to 0. -
:key_prefix
- Prefix for keys used in Redis, e.g.myapp:
-
:expire_after
- A number in seconds for session timeout
-
-
:on_sid_collision:
- Called with SID string when generated SID collides -
:on_redis_down:
- Called with err, env, and SID on Errno::ECONNREFUSED -
:on_session_load_error:
- Called with err and SID on Marshal.load fail -
:serializer:
- Serializer to use on session data, default is :marshal.
Examples
My::Application.config.session_store :redis_session_store, {
key: 'your_session_key',
redis: {
db: 2,
expire_after: 120.minutes,
key_prefix: 'myapp:session:',
host: 'host', # Redis host name, default is localhost
port: 12345 # Redis port, default is 6379
},
on_sid_collision: ->(sid) { logger.warn("SID collision! #{sid}") },
on_redis_down: ->(*a) { logger.error("Redis down! #{a.inspect}") }
serializer: :hybrid # migrate from Marshal to JSON
}
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/redis-session-store.rb', line 42 def initialize(app, = {}) super = [:redis] || {} @default_options.merge!(namespace: 'rack:session') @default_options.merge!() @redis = Redis.new() @on_sid_collision = [:on_sid_collision] @on_redis_down = [:on_redis_down] @serializer = determine_serializer([:serializer]) @on_session_load_error = [:on_session_load_error] verify_handlers! end |
Instance Attribute Details
#on_redis_down ⇒ Object
Returns the value of attribute on_redis_down.
57 58 59 |
# File 'lib/redis-session-store.rb', line 57 def on_redis_down @on_redis_down end |
#on_session_load_error ⇒ Object
Returns the value of attribute on_session_load_error.
57 58 59 |
# File 'lib/redis-session-store.rb', line 57 def on_session_load_error @on_session_load_error end |
#on_sid_collision ⇒ Object
Returns the value of attribute on_sid_collision.
57 58 59 |
# File 'lib/redis-session-store.rb', line 57 def on_sid_collision @on_sid_collision end |