Class: Riak::SessionStore

Inherits:
Rack::Session::Abstract::ID
  • Object
show all
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)

Instance Method Summary (collapse)

Constructor Details

- (SessionStore) initialize(app, options = {})

Creates a new Riak::SessionStore middleware

Parameters:

  • app

    the Rack application

  • options (Hash) (defaults to: {})

    configuration options

See Also:

  • Rack::Session::Abstract::ID#initialize


51
52
53
54
55
56
57
58
# File 'riak-sessions/lib/riak/session_store.rb', line 51

def initialize(app, options={})
  super
  @riak_options = options.merge(DEFAULT_OPTIONS)
  @client = Riak::Client.new(@default_options.slice(*Riak::Client::VALID_OPTIONS))
  @bucket = @client.bucket(default_options[: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