Skip to content

Commit

Permalink
Add docs for serializer option #25
Browse files Browse the repository at this point in the history
  • Loading branch information
dplummer committed Mar 17, 2014
1 parent 94f2118 commit 80f102e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ My::Application.config.session_store = :redis_session_store, {
}
```

### Serializer

By default the Marshal serializer is used. With Rails 4, you can use JSON as a
custom serializer:

* `:json` - serialize cookie values with `JSON` (Requires Rails 4+)
* `:marshal` - serialize cookie values with `Marshal` (Default)
* `:hybrid` - transparently migrate existing `Marshal` cookie values to `JSON` (Requires Rails 4+)
* `CustomClass` - You can just pass the constant name of any class that responds to `.load` and `.dump`

``` ruby
My::Application.config.session_store = :redis_session_store, {
# ... other options ...
serializer: :hybrid
}
```

**Note**: Rails 4 is required for using the `:json` and `:hybrid` serializers
because the `Flash` object doesn't serializer well in 3.2. See [Rails
#13945](https://github.com/rails/rails/pull/13945) for more info.

Contributing, Authors, & License
--------------------------------

Expand Down
2 changes: 2 additions & 0 deletions lib/redis-session-store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
# * +: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
# * +:serializer:+ - Serializer to use on session data, default is :marshal.
#
# ==== Examples
#
Expand All @@ -30,6 +31,7 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
# },
# 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
# }
#
def initialize(app, options = {})
Expand Down

0 comments on commit 80f102e

Please sign in to comment.