Class: Rack::Session::RiakPool

Inherits:
Object
  • Object
show all
Defined in:
lib/riak_sessions.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options = {}) ⇒ RiakPool

Returns a new instance of RiakPool.



15
16
17
18
19
# File 'lib/riak_sessions.rb', line 15

def initialize(host, port, options={})
  @host= host
  @port = port
  @path ='/raw/riak_session'
end

Instance Method Details

#[](session_id) ⇒ Object



21
22
23
# File 'lib/riak_sessions.rb', line 21

def [](session_id)
  get(session_id)
end

#delete(session_id) ⇒ Object



45
46
47
48
# File 'lib/riak_sessions.rb', line 45

def delete(session_id)
  req = Net::HTTP::Delete.new([@path, session_id].join('/'))
  Net::HTTP.start(@host, @port) { |http| http.request(req) }
end

#get(session_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/riak_sessions.rb', line 25

def get(session_id)
  req = Net::HTTP::Get.new([@path, session_id].join('/'))
  res = Net::HTTP.start(@host, @port) { |http| http.request(req) }
  return Marshal.load(res.body)
rescue Net::HTTPNotFound => e
  return nil
end

#set(session_id, data) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/riak_sessions.rb', line 37

def set(session_id, data)
  req = Net::HTTP::Put.new([@path, session_id].join('/'))
  req.content_type = 'application/octet-stream'
  req.body = Marshal.dump(data)
  Net::HTTP.start(@host, @port) { |http| http.request(req) }
  return true
end

#store(session_id, data) ⇒ Object



33
34
35
# File 'lib/riak_sessions.rb', line 33

def store(session_id, data)
  set(session_id, data)
end