Class: Riak::SessionStore
- Inherits:
-
Rack::Session::Abstract::ID
- Object
- Rack::Session::Abstract::ID
- Riak::SessionStore
- Defined in:
- riak-sessions/lib/riak/session_store.rb
Overview
Lets you store web application session data in Riak. Useful for those cases where you need more than the 4K that cookies provide.
Usage (Rack builder):
use Riak::SessionStore
Usage (Rails):
config.middleware.use Riak::SessionStore
Usage (Rails 2.3), requires you to swap out the default store:
config.middleware.swap ActionController::Session::CookieStore, Riak::SessionStore
For configuration options, see #initialize.
Constant Summary
- DEFAULT_OPTIONS =
Rack::Session::Abstract::ID::DEFAULT_OPTIONS.merge \ :host => "127.0.0.1", :http_port => 8098, :bucket => "_sessions", :r => 1, :w => 1, :dw => 0, :rw => 1, :n_val => 2, :last_write_wins => false, :content_type => "application/x-ruby-marshal"
Instance Attribute Summary (collapse)
-
- (Object) bucket
readonly
Returns the value of attribute bucket.
Instance Method Summary (collapse)
- - (Object) generate_sid
-
- (SessionStore) initialize(app, options = {})
constructor
Creates a new Riak::SessionStore middleware.
Constructor Details
- (SessionStore) initialize(app, options = {})
Creates a new Riak::SessionStore middleware
51 52 53 54 55 56 57 58 |
# File 'riak-sessions/lib/riak/session_store.rb', line 51 def initialize(app, ={}) super @riak_options = .merge(DEFAULT_OPTIONS) @client = Riak::Client.new(@default_options.slice(*Riak::Client::VALID_OPTIONS)) @bucket = @client.bucket([:bucket]) set_bucket_defaults self end |
Instance Attribute Details
- (Object) bucket (readonly)
Returns the value of attribute bucket
45 46 47 |
# File 'riak-sessions/lib/riak/session_store.rb', line 45 def bucket @bucket end |
Instance Method Details
- (Object) generate_sid
60 61 62 63 64 65 |
# File 'riak-sessions/lib/riak/session_store.rb', line 60 def generate_sid loop do sid = super break sid unless @bucket.exists?(sid) end end |