Permalink
Browse files

renaming things

  • Loading branch information...
nofxx committed Jul 19, 2009
1 parent 42077ef commit 9469e91fa074606b9b5e8e4c54e8b87dcff26cd7
View
@@ -8,8 +8,13 @@ Demo:: http://github.com/nofxx/tokyo_webapps under rails/tokyo_store
== Require
-Tokyo Cabinet/Tyrant:: http://tokyocabinet.sourceforge.net
-Rufus Tokyo:: http://github.com/jmettraux/rufus-tokyo
+Tokyo Cabinet and/or Tyrant:: http://tokyocabinet.sourceforge.net
+
+Choose an adapter:
+
+Tyrant - Pure Ruby:: http://tokyocabinet.sourceforge.net/tyrantrubydoc
+Cabinet - C Bindings:: http://tokyocabinet.sourceforge.net/rubydoc
+RufusTyrant - Rufus FFI:: http://github.com/jmettraux/rufus-tokyo
== Install
@@ -19,12 +24,17 @@ Rufus Tokyo:: http://github.com/jmettraux/rufus-tokyo
Rails (enviroment.rb)
config.gem 'nofxx-tokyo_store', :lib => 'tokyo_store'
- ActionController::Base.session_store = Rack::Session::Tokyo
+ ActionController::Base.session_store = Rack::Session::<ADAPTER (Tyrant, Cabinet or RufusTyrant)>
+
-Start Tyrant
+== Tyrant
+
+Start the server if you are using a Tyrant based adapter:
ttserver data.tch
+Some rake tasks: http://gist.github.com/147413
+
Have fun!
@@ -33,7 +43,7 @@ Have fun!
Mikio Hirabayashi:: tokyo products
John Mettraux:: rufus-tokyo
-Luca Guidi:: redis-store - Rack code stolen from here =D
+Luca Guidi:: redis-store
== Copyright
@@ -1,6 +1,8 @@
+require 'rufus/tokyo/tyrant'
+
module Rack
module Session
- class Tokyo < Abstract::ID
+ class RufusTyrant < Abstract::ID
attr_reader :mutex, :pool
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge :tyrant_server => "localhost:1978"
@@ -9,20 +9,19 @@ class Tyrant < Abstract::ID
def initialize(app, options = {})
super
@mutex = Mutex.new
- @host, @port = *(options[:tyrant_server] || @default_options[:tyrant_server]).split(":") # @default_options) #options[:cache] ||
+ @host, @port = *(options[:tyrant_server] || @default_options[:tyrant_server]).split(":")
tokyo_connect
end
private
def tokyo_connect
@pool = RDB.new
unless @pool.open(@host, @port.to_i)
- warn "Can't connect to Tyrant #{e}"
+ warn "Can't connect to Tyrant #{@host}:#{@port}"
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
@@ -38,11 +37,9 @@ def get_session(env, sid)
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]
@@ -60,7 +57,6 @@ def set_session(env, sid, new_session, options)
warn $!.inspect
ensure
@mutex.unlock if env['rack.multithread']
- # @pool.close
end
def generate_sid
View
@@ -1,9 +1,10 @@
-require 'rufus/tokyo/tyrant'
# Rack Session
if defined?(Rack::Session)
require "rack/session/abstract/id"
- require "rack/session/tokyo"
+ require "rack/session/tyrant"
+ #require "rack/session/cabinet"
+ #require "rack/session/rufus_tyrant"
end
# # Cache store
@@ -3,9 +3,6 @@
module Rack
module Session
- # class Tokyo
- # attr_reader :
- # end
describe "Rack::Session::Cabinet" do
before(:each) do
@session_key = Rack::Session::Cabinet::DEFAULT_OPTIONS[:key]
@@ -32,8 +29,8 @@ module Session
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.host.should eql("127.0.0.1")
- pool.port.should eql(1978)
+ 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)
@@ -3,12 +3,9 @@
module Rack
module Session
- # class Tokyo
- # attr_reader :
- # end
- describe "Rack::Session::Tokyo" do
+ describe "Rack::Session::RufusTyrant" do
before(:each) do
- @session_key = Rack::Session::Tokyo::DEFAULT_OPTIONS[:key]
+ @session_key = Rack::Session::RufusTyrant::DEFAULT_OPTIONS[:key]
@session_match = /#{@session_key}=[0-9a-fA-F]+;/
@incrementor = lambda do |env|
env["rack.session"]["counter"] ||= 0
@@ -30,30 +27,30 @@ module Session
end
it "should specify connection params" do
- pool = Rack::Session::Tokyo.new(@incrementor, :tyrant_server => "127.0.0.1:1978").pool
+ pool = Rack::Session::RufusTyrant.new(@incrementor, :tyrant_server => "127.0.0.1:1978").pool
pool.should be_kind_of(Rufus::Tokyo::Tyrant)
pool.host.should eql("127.0.0.1")
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::RufusTyrant.new(@incrementor, :tokyo_server => ["localhost:6379", "localhost:6380"]).pool
+ # pool.should be_kind_of(DistributedMarshaledRufusTyrant)
end
it "should raise tokyo error on connect" do
- lambda{ Rack::Session::Tokyo.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
- should_not raise_error(Rufus::Tokyo::TokyoError)
+ lambda{ Rack::Session::RufusTyrant.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
+ should raise_error(Rufus::Tokyo::TokyoError)
end
it "creates a new cookie" do
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
res = Rack::MockRequest.new(pool).get("/")
res["Set-Cookie"].should match(/#{@session_key}=/)
res.body.should eql('{"counter"=>1}')
end
it "determines session from a cookie" do
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
req = Rack::MockRequest.new(pool)
res = req.get("/")
cookie = res["Set-Cookie"]
@@ -63,7 +60,7 @@ module Session
it "survives nonexistant cookies" do
bad_cookie = "rack.session=blsarghfasel"
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
res = Rack::MockRequest.new(pool).get("/", "HTTP_COOKIE" => bad_cookie)
res.body.should eql('{"counter"=>1}')
cookie = res["Set-Cookie"][@session_match]
@@ -72,7 +69,7 @@ module Session
# Expire isn't supported by cabinet. Implement in ruby?
# it "should maintain freshness" do
- # pool = Rack::Session::Tokyo.new(@incrementor, :expire_after => 3)
+ # pool = Rack::Session::RufusTyrant.new(@incrementor, :expire_after => 3)
# res = Rack::MockRequest.new(pool).get('/')
# res.body.should include('"counter"=>1')
# cookie = res["Set-Cookie"]
@@ -87,7 +84,7 @@ module Session
# end
it "deletes cookies with :drop option" do
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
req = Rack::MockRequest.new(pool)
drop = Rack::Utils::Context.new(pool, @drop_session)
dreq = Rack::MockRequest.new(drop)
@@ -110,7 +107,7 @@ module Session
end
it "provides new session id with :renew option" do
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
req = Rack::MockRequest.new(pool)
renew = Rack::Utils::Context.new(pool, @renew_session)
rreq = Rack::MockRequest.new(renew)
@@ -135,7 +132,7 @@ module Session
end
specify "omits cookie with :defer option" do
- pool = Rack::Session::Tokyo.new(@incrementor)
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
req = Rack::MockRequest.new(pool)
defer = Rack::Utils::Context.new(pool, @defer_session)
dreq = Rack::MockRequest.new(defer)
@@ -160,8 +157,8 @@ module Session
# anyone know how to do this better?
specify "multithread: should cleanly merge sessions" do
next unless $DEBUG
- warn 'Running multithread test for Session::Tokyo'
- pool = Rack::Session::Tokyo.new(@incrementor)
+ warn 'Running multithread test for Session::RufusTyrant'
+ pool = Rack::Session::RufusTyrant.new(@incrementor)
req = Rack::MockRequest.new(pool)
res = req.get('/')
@@ -242,7 +239,7 @@ module Session
end
after(:all) do
- Rack::Session::Tokyo.new(@incrementor).pool.clear
+ Rack::Session::RufusTyrant.new(@incrementor).pool.clear
end
end
end
@@ -3,9 +3,9 @@
module Rack
module Session
- # class Tokyo
- # attr_reader :
- # end
+ class Tyrant
+ attr_reader :host, :port
+ end
describe "Rack::Session::Tyrant" do
before(:each) do
@session_key = Rack::Session::Tyrant::DEFAULT_OPTIONS[:key]
@@ -30,18 +30,18 @@ module Session
end
it "should specify connection params" do
- pool = Rack::Session::Tyrant.new(@incrementor, :tyrant_server => "127.0.0.1:1978").pool
+ 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.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::Tyrant.new(@incrementor, :tokyo_server => ["localhost:6379", "localhost:6380"]).pool
+ # pool.should be_kind_of(DistributedMarshaledTyrant)
end
- it "should raise tokyo error on connect" do
- lambda{ Rack::Session::Tokyo.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
- should_not raise_error(Rufus::Tokyo::TokyoError)
+ it "should not raise error on connect" do
+ lambda{ Rack::Session::Tyrant.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
+ should_not raise_error
end
View
@@ -1,7 +1,7 @@
$: << File.join(File.dirname(__FILE__), "/../lib")
%W{rubygems spec rack/cache activesupport }.each { |l| require l }
require 'tokyo_store'
-require 'rack/session/tokyo'
+require 'rack/session/rufus_tyrant'
require 'rack/session/tyrant'
require 'rack/session/cabinet'
require 'cache/tokyo_store'
View
@@ -25,13 +25,13 @@ Gem::Specification.new do |s|
"lib/rack/cache/tokyo_entitystore.rb",
"lib/rack/cache/tokyo_metastore.rb",
"lib/rack/session/cabinet.rb",
- "lib/rack/session/tokyo.rb",
+ "lib/rack/session/rufus_tyrant.rb",
"lib/rack/session/tyrant.rb",
"lib/tokyo_store.rb",
"spec/cache/tokyo_store_spec.rb",
"spec/rack/cache/tokyo_spec.rb",
"spec/rack/session/cabinet_spec.rb",
- "spec/rack/session/tokyo_spec.rb",
+ "spec/rack/session/rufus_tyrant_spec.rb",
"spec/rack/session/tyrant_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
s.summary = %q{Tokyo Tyrant rails session store}
s.test_files = [
"spec/rack/cache/tokyo_spec.rb",
- "spec/rack/session/tokyo_spec.rb",
+ "spec/rack/session/rufus_tyrant_spec.rb",
"spec/rack/session/cabinet_spec.rb",
"spec/rack/session/tyrant_spec.rb",
"spec/tokyo_store_spec.rb",

0 comments on commit 9469e91

Please sign in to comment.