nofxx-tokyo_store 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rack/session/tokyo.rb +13 -31
- data/spec/rack/session/tokyo_spec.rb +11 -2
- data/tokyo_store.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rack/session/tokyo.rb
CHANGED
@@ -7,18 +7,22 @@ module Rack
|
|
7
7
|
def initialize(app, options = {})
|
8
8
|
super
|
9
9
|
@mutex = Mutex.new
|
10
|
-
host, port = *options[:tyrant_server] || @default_options[:tyrant_server].split(":") # @default_options) #options[:cache] ||
|
10
|
+
@host, @port = *(options[:tyrant_server] || @default_options[:tyrant_server]).split(":") # @default_options) #options[:cache] ||
|
11
|
+
tokyo_connect
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def tokyo_connect
|
11
16
|
begin
|
12
|
-
@pool =
|
13
|
-
rescue => e
|
14
|
-
"
|
17
|
+
@pool = Rufus::Tokyo::Tyrant.new(@host, @port.to_i)
|
18
|
+
rescue Rufus::Tokyo::TokyoError => e
|
19
|
+
warn "Can't connect to Tyrant #{e}"
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
private
|
19
23
|
def get_session(env, sid)
|
20
24
|
@mutex.lock if env['rack.multithread']
|
21
|
-
session = Marshal.load(@pool[sid]) rescue session if sid
|
25
|
+
session = Marshal.load(@pool[sid]) rescue session if sid && session = @pool[sid]
|
22
26
|
unless sid && session
|
23
27
|
env['rack.errors'].puts("Session '#{sid.inspect}' not found, initializing...") if $VERBOSE and not sid.nil?
|
24
28
|
session = {}
|
@@ -28,7 +32,7 @@ module Rack
|
|
28
32
|
end
|
29
33
|
session.instance_variable_set('@old', {}.merge(session))
|
30
34
|
return [sid, session]
|
31
|
-
rescue => e
|
35
|
+
rescue Rufus::Tokyo::TokyoError => e
|
32
36
|
session = {}
|
33
37
|
ensure
|
34
38
|
@mutex.unlock if env['rack.multithread']
|
@@ -44,38 +48,16 @@ module Rack
|
|
44
48
|
@pool[sid] = ""
|
45
49
|
end
|
46
50
|
old_session = new_session.instance_variable_get('@old') || {}
|
47
|
-
session =
|
51
|
+
session = new_session
|
48
52
|
@pool[sid] = options && options[:raw] ? session : Marshal.dump(session)
|
49
53
|
return sid
|
50
|
-
rescue => e
|
51
|
-
if e =~ /refused/
|
54
|
+
rescue Rufus::Tokyo::TokyoError => e
|
52
55
|
warn "#{self} is unable to find server, error: #{e}"
|
53
56
|
warn $!.inspect
|
54
|
-
return false
|
55
|
-
else
|
56
|
-
raise e
|
57
|
-
end
|
58
57
|
ensure
|
59
58
|
@mutex.unlock if env['rack.multithread']
|
60
59
|
end
|
61
60
|
|
62
|
-
def merge_sessions(sid, old, new, cur={})
|
63
|
-
unless Hash === old and Hash === new
|
64
|
-
warn 'Bad old or new sessions provided.'
|
65
|
-
return cur
|
66
|
-
end
|
67
|
-
|
68
|
-
delete = old.keys - new.keys
|
69
|
-
warn "//@#{sid}: dropping #{delete*','}" if $DEBUG and not delete.empty?
|
70
|
-
delete.each{|k| cur.delete k }
|
71
|
-
|
72
|
-
update = new.keys.select{|k| new[k] != old[k] }
|
73
|
-
warn "//@#{sid}: updating #{update*','}" if $DEBUG and not update.empty?
|
74
|
-
update.each{|k| cur[k] = new[k] }
|
75
|
-
|
76
|
-
cur
|
77
|
-
end
|
78
|
-
|
79
61
|
def generate_sid
|
80
62
|
loop do
|
81
63
|
sid = super
|
@@ -3,6 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
|
4
4
|
module Rack
|
5
5
|
module Session
|
6
|
+
# class Tokyo
|
7
|
+
# attr_reader :
|
8
|
+
# end
|
6
9
|
describe "Rack::Session::Tokyo" do
|
7
10
|
before(:each) do
|
8
11
|
@session_key = Rack::Session::Tokyo::DEFAULT_OPTIONS[:key]
|
@@ -27,15 +30,21 @@ module Rack
|
|
27
30
|
end
|
28
31
|
|
29
32
|
it "should specify connection params" do
|
30
|
-
pool = Rack::Session::Tokyo.new(@incrementor, :
|
33
|
+
pool = Rack::Session::Tokyo.new(@incrementor, :tyrant_server => "127.0.0.1:1978").pool
|
31
34
|
pool.should be_kind_of(Rufus::Tokyo::Tyrant)
|
32
|
-
pool.host.should eql("
|
35
|
+
pool.host.should eql("127.0.0.1")
|
33
36
|
pool.port.should eql(1978)
|
34
37
|
|
35
38
|
# pool = Rack::Session::Tokyo.new(@incrementor, :tokyo_server => ["localhost:6379", "localhost:6380"]).pool
|
36
39
|
# pool.should be_kind_of(DistributedMarshaledTokyo)
|
37
40
|
end
|
38
41
|
|
42
|
+
it "should raise tokyo error on connect" do
|
43
|
+
lambda{ Rack::Session::Tokyo.new(@incrementor, :tyrant_server => "localhost:6380").pool }.
|
44
|
+
should_not raise_error(Rufus::Tokyo::TokyoError)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
39
48
|
it "creates a new cookie" do
|
40
49
|
pool = Rack::Session::Tokyo.new(@incrementor)
|
41
50
|
res = Rack::MockRequest.new(pool).get("/")
|
data/tokyo_store.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{tokyo_store}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Marcos Piccinini"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-06}
|
10
10
|
s.email = %q{x@nofxx.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nofxx-tokyo_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|