Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

packing 0.3.0

  • Loading branch information...
commit 1c372e6c3a160ea7f96ab0835b607510837251ff 1 parent 9469e91
@nofxx authored
View
2  VERSION
@@ -1 +1 @@
-0.2.1
+0.3.0
View
15 lib/rack/session/cabinet.rb
@@ -4,7 +4,7 @@ module Session
class Cabinet < Abstract::ID
include TokyoCabinet
attr_reader :mutex, :pool
- DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :cabinet_file => "session_cabinet.tch"
+ DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :cabinet_file => "/tmp/session.tch"
def initialize(app, options = {})
super
@@ -16,13 +16,12 @@ def initialize(app, options = {})
private
def tokyo_connect
@pool = HDB.new
- unless @pool.open(@db, HDB::OWRITER | HDB::OCREAT)
- warn "Can't open db file #{@db}"
+ unless @pool.open(@db, HDB::OREADER | HDB::OWRITER | HDB::OCREAT)
+ warn "Can't open db file '#{@db}', #{@pool.errmsg}."
end
end
def get_session(env, sid)
- # tokyo_connect
session = Marshal.load(@pool.get(sid)) rescue session if sid && session = @pool.get(sid)
@mutex.lock if env['rack.multithread']
unless sid && session
@@ -32,17 +31,14 @@ def get_session(env, sid)
ret = @pool.put(sid, Marshal.dump(session))
raise "Session collision on '#{sid.inspect}'" unless ret
end
- #session.instance_variable_put('@old', {}.merge(session))
return [sid, session]
rescue Rufus::Tokyo::TokyoError => e
return [nil, {}]
ensure
@mutex.unlock if env['rack.multithread']
- # @pool.close
end
def set_session(env, sid, new_session, options)
- # tokyo_connect
@mutex.lock if env['rack.multithread']
session = Marshal.load(session) rescue session if session = @pool.get(sid)
if options[:renew] || options[:drop]
@@ -51,16 +47,13 @@ def set_session(env, sid, new_session, options)
sid = generate_sid
@pool.put(sid, "")
end
- #old_session = new_session.instance_variable_get('@old') || {}
- session = new_session
- @pool.put(sid, options && options[:raw] ? session : Marshal.dump(session))
+ @pool.put(sid, options && options[:raw] ? new_session : Marshal.dump(new_session))
return sid
rescue Rufus::Tokyo::TokyoError => e
warn "#{self} is unable to find server, error: #{e}"
warn $!.inspect
ensure
@mutex.unlock if env['rack.multithread']
- # @pool.close
end
def generate_sid
View
19 lib/rack/session/rufus_tyrant.rb
@@ -13,20 +13,17 @@ def initialize(app, options = {})
# connecting & closing on each get and put
# not sure if this is the best option, but otherwise it'll keep
# opening connections until tyrant freezes... =/
- # tokyo_connect
- # tokyo_connect
- p @pool
- @pool ||= Rufus::Tokyo::Tyrant.new(@host, @port.to_i)
+ tokyo_connect
end
private
- # def tokyo_connect
- # begin
-
- # rescue Rufus::Tokyo::TokyoError => e
- # warn "Can't connect to Tyrant #{e}"
- # end
- # end
+ def tokyo_connect
+ begin
+ @pool ||= Rufus::Tokyo::Tyrant.new(@host, @port.to_i)
+ rescue Rufus::Tokyo::TokyoError => e
+ warn "Can't connect to Tyrant #{e}"
+ end
+ end
def get_session(env, sid)
# tokyo_connect
View
5 lib/rack/session/tyrant.rb
@@ -31,7 +31,6 @@ def get_session(env, sid)
ret = @pool.put(sid, Marshal.dump(session))
raise "Session collision on '#{sid.inspect}'" unless ret
end
- #session.instance_variable_put('@old', {}.merge(session))
return [sid, session]
rescue Rufus::Tokyo::TokyoError => e
return [nil, {}]
@@ -48,9 +47,7 @@ def set_session(env, sid, new_session, options)
sid = generate_sid
@pool.put(sid, "")
end
- #old_session = new_session.instance_variable_get('@old') || {}
- session = new_session
- @pool.put(sid, options && options[:raw] ? session : Marshal.dump(session))
+ @pool.put(sid, options && options[:raw] ? new_session : Marshal.dump(new_session))
return sid
rescue Rufus::Tokyo::TokyoError => e
warn "#{self} is unable to find server, error: #{e}"
View
12 spec/rack/session/cabinet_spec.rb
@@ -27,17 +27,13 @@ module Session
end
it "should specify connection params" do
- pool = Rack::Session::Cabinet.new(@incrementor, :cabinet_file => "some.tch").pool
- # pool.should be_kind_of(Rufus::Tokyo::Cabinet)
- pool.path.should eql("some.tch")
- # pool.port.should eql(1978)
-
- # pool = Rack::Session::Tokyo.new(@incrementor, :tokyo_server => ["localhost:6379", "localhost:6380"]).pool
- # pool.should be_kind_of(DistributedMarshaledTokyo)
+ pool = Rack::Session::Cabinet.new(@incrementor, :cabinet_file => "/tmp/some.tch").pool
+ pool.should be_kind_of(TokyoCabinet::HDB)
+ pool.path.should eql("/tmp/some.tch")
end
it "should raise tokyo error on connect" do
- lambda{ Rack::Session::Tokyo.new(@incrementor, :cabinet_file => "session.tch").pool }.
+ lambda{ Rack::Session::Tokyo.new(@incrementor, :cabinet_file => "/tmp/session.tch").pool }.
should_not raise_error(Rufus::Tokyo::TokyoError)
end
View
2  spec/rack/session/rufus_tyrant_spec.rb
@@ -38,7 +38,7 @@ module Session
it "should raise tokyo error on connect" do
lambda{ Rack::Session::RufusTyrant.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
- should raise_error(Rufus::Tokyo::TokyoError)
+ should_not raise_error(Rufus::Tokyo::TokyoError)
end
View
8 spec/rack/session/tyrant_spec.rb
@@ -30,10 +30,10 @@ class Tyrant
end
it "should specify connection params" do
- pool = Rack::Session::Tyrant.new(@incrementor, :tyrant_server => "127.0.0.1:1978")
- # pool.should be_kind_of(Rufus::Tokyo::Tyrant)
- pool.host.should eql("127.0.0.1")
- pool.port.should eql("1978")
+ pool = Rack::Session::Tyrant.new(@incrementor, :tyrant_server => "127.0.0.1:1978").pool
+ pool.should be_kind_of(TokyoTyrant::RDB)
+ #pool.host.should eql("127.0.0.1")
+ #pool.port.should eql("1978")
# pool = Rack::Session::Tyrant.new(@incrementor, :tokyo_server => ["localhost:6379", "localhost:6380"]).pool
# pool.should be_kind_of(DistributedMarshaledTyrant)
View
2  tokyo_store.gemspec
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{tokyo_store}
- s.version = "0.2.1"
+ s.version = "0.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Marcos Piccinini"]
Please sign in to comment.
Something went wrong with that request. Please try again.