redis-rack 0.0.0 → 1.3.5.rc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/Rakefile +8 -1
- data/lib/rack/session/redis.rb +69 -0
- data/lib/redis/rack/version.rb +6 -0
- data/lib/redis-rack.rb +3 -7
- data/redis-rack.gemspec +12 -6
- data/test/rack/session/redis_test.rb +289 -0
- data/test/redis/rack/version_test.rb +7 -0
- data/test/test_helper.rb +7 -0
- metadata +111 -45
- data/lib/redis-rack/version.rb +0 -5
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 - 2011 Luca Guidi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Redis stores for Rack
|
2
|
+
|
3
|
+
__`redis-rack`__ provides a Redis backed session store __Rack__. It natively supports object marshalling, timeouts, single or multiple nodes and namespaces.
|
4
|
+
|
5
|
+
## Redis Installation
|
6
|
+
|
7
|
+
### Option 1: Homebrew
|
8
|
+
|
9
|
+
MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
|
10
|
+
|
11
|
+
brew install redis
|
12
|
+
|
13
|
+
### Option 2: From Source
|
14
|
+
|
15
|
+
Download and install Redis from [http://redis.io](http://redis.io/)
|
16
|
+
|
17
|
+
wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
|
18
|
+
tar -zxf redis-2.4.5.tar.gz
|
19
|
+
mv redis-2.4.5 redis
|
20
|
+
cd redis
|
21
|
+
make
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
# Gemfile
|
26
|
+
gem 'redis-rack'
|
27
|
+
|
28
|
+
### Session Store:
|
29
|
+
|
30
|
+
# config.ru
|
31
|
+
require 'rack'
|
32
|
+
require 'rack/session/redis'
|
33
|
+
|
34
|
+
use Rack::Session::Redis
|
35
|
+
|
36
|
+
#### Configuration
|
37
|
+
|
38
|
+
For advanced configuration options, please check the [Redis Store Wiki](https://github.com/jodosha/redis-store/wiki).
|
39
|
+
|
40
|
+
## Running tests
|
41
|
+
|
42
|
+
git clone git://github.com/jodosha/redis-store.git
|
43
|
+
cd redis-store/redis-rack
|
44
|
+
gem install bundler --pre # required version: 1.1.rc
|
45
|
+
bundle exec rake
|
46
|
+
|
47
|
+
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
|
48
|
+
|
49
|
+
## Copyright
|
50
|
+
|
51
|
+
(c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
|
data/Rakefile
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rack/session/abstract/id'
|
2
|
+
require 'redis-store'
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
module Session
|
7
|
+
class Redis < Abstract::ID
|
8
|
+
attr_reader :mutex, :pool
|
9
|
+
|
10
|
+
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge \
|
11
|
+
:redis_server => 'redis://127.0.0.1:6379/0/rack:session'
|
12
|
+
|
13
|
+
def initialize(app, options = {})
|
14
|
+
super
|
15
|
+
|
16
|
+
@mutex = Mutex.new
|
17
|
+
@pool = ::Redis::Factory.create @default_options[:redis_server]
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_sid
|
21
|
+
loop do
|
22
|
+
sid = super
|
23
|
+
break sid unless @pool.get(sid)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_session(env, sid)
|
28
|
+
with_lock(env, [nil, {}]) do
|
29
|
+
unless sid and session = @pool.get(sid)
|
30
|
+
sid, session = generate_sid, {}
|
31
|
+
unless /^OK/ =~ @pool.set(sid, session)
|
32
|
+
raise "Session collision on '#{sid.inspect}'"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
[sid, session]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_session(env, session_id, new_session, options)
|
40
|
+
with_lock(env, false) do
|
41
|
+
@pool.set session_id, new_session, options
|
42
|
+
session_id
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def destroy_session(env, session_id, options)
|
47
|
+
with_lock(env) do
|
48
|
+
@pool.del(session_id)
|
49
|
+
generate_sid unless options[:drop]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def with_lock(env, default=nil)
|
54
|
+
@mutex.lock if env['rack.multithread']
|
55
|
+
yield
|
56
|
+
rescue Errno::ECONNREFUSED
|
57
|
+
if $VERBOSE
|
58
|
+
warn "#{self} is unable to find Redis server."
|
59
|
+
warn $!.inspect
|
60
|
+
end
|
61
|
+
default
|
62
|
+
ensure
|
63
|
+
@mutex.unlock if @mutex.locked?
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/lib/redis-rack.rb
CHANGED
data/redis-rack.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "redis
|
3
|
+
require "redis/rack/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "redis-rack"
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Luca Guidi"]
|
9
9
|
s.email = ["guidi.luca@gmail.com"]
|
10
10
|
s.homepage = "http://jodosha.github.com/redis-store"
|
11
|
-
s.summary = %q{Redis for Rack}
|
12
|
-
s.description = %q{Redis for Rack}
|
11
|
+
s.summary = %q{Redis Store for Rack}
|
12
|
+
s.description = %q{Redis Store for Rack}
|
13
13
|
|
14
14
|
s.rubyforge_project = "redis-rack"
|
15
15
|
|
@@ -18,7 +18,13 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
s.add_runtime_dependency 'redis-store', '1.1.0.rc2'
|
22
|
+
s.add_runtime_dependency 'rack', '1.3.5'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rake', '~> 0.9.2.2'
|
25
|
+
s.add_development_dependency 'bundler', '~> 1.1.rc'
|
26
|
+
s.add_development_dependency 'mocha', '~> 0.10.0'
|
27
|
+
s.add_development_dependency 'minitest', '~> 2.8.0'
|
28
|
+
s.add_development_dependency 'purdytest', '~> 1.0.0'
|
24
29
|
end
|
30
|
+
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
describe Rack::Session::Redis do
|
6
|
+
session_key = Rack::Session::Redis::DEFAULT_OPTIONS[:key]
|
7
|
+
session_match = /#{session_key}=([0-9a-fA-F]+);/
|
8
|
+
incrementor = lambda do |env|
|
9
|
+
env["rack.session"]["counter"] ||= 0
|
10
|
+
env["rack.session"]["counter"] += 1
|
11
|
+
Rack::Response.new(env["rack.session"].inspect).to_a
|
12
|
+
end
|
13
|
+
drop_session = proc do |env|
|
14
|
+
env['rack.session.options'][:drop] = true
|
15
|
+
incrementor.call(env)
|
16
|
+
end
|
17
|
+
renew_session = proc do |env|
|
18
|
+
env['rack.session.options'][:renew] = true
|
19
|
+
incrementor.call(env)
|
20
|
+
end
|
21
|
+
defer_session = proc do |env|
|
22
|
+
env['rack.session.options'][:defer] = true
|
23
|
+
incrementor.call(env)
|
24
|
+
end
|
25
|
+
|
26
|
+
# # test Redis connection
|
27
|
+
# Rack::Session::Redis.new(incrementor)
|
28
|
+
#
|
29
|
+
# it "faults on no connection" do
|
30
|
+
# lambda{
|
31
|
+
# Rack::Session::Redis.new(incrementor, :redis_server => 'nosuchserver')
|
32
|
+
# }.must_raise(Exception)
|
33
|
+
# end
|
34
|
+
|
35
|
+
it "uses the default Redis server and namespace when not provided" do
|
36
|
+
pool = Rack::Session::Redis.new(incrementor)
|
37
|
+
pool.pool.to_s.must_match(/127\.0\.0\.1:6379 against DB 0 with namespace rack:session$/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "uses the specified namespace when provided" do
|
41
|
+
pool = Rack::Session::Redis.new(incrementor, :redis_server => {:namespace => 'test:rack:session'})
|
42
|
+
pool.pool.to_s.must_match(/namespace test:rack:session$/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "uses the specified Redis server when provided" do
|
46
|
+
pool = Rack::Session::Redis.new(incrementor, :redis_server => 'redis://127.0.0.1:6380/1')
|
47
|
+
pool.pool.to_s.must_match(/127\.0\.0\.1:6380 against DB 1$/)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "creates a new cookie" do
|
51
|
+
pool = Rack::Session::Redis.new(incrementor)
|
52
|
+
res = Rack::MockRequest.new(pool).get("/")
|
53
|
+
res["Set-Cookie"].must_include("#{session_key}=")
|
54
|
+
res.body.must_equal('{"counter"=>1}')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "determines session from a cookie" do
|
58
|
+
pool = Rack::Session::Redis.new(incrementor)
|
59
|
+
req = Rack::MockRequest.new(pool)
|
60
|
+
res = req.get("/")
|
61
|
+
cookie = res["Set-Cookie"]
|
62
|
+
req.get("/", "HTTP_COOKIE" => cookie).
|
63
|
+
body.must_equal('{"counter"=>2}')
|
64
|
+
req.get("/", "HTTP_COOKIE" => cookie).
|
65
|
+
body.must_equal('{"counter"=>3}')
|
66
|
+
end
|
67
|
+
|
68
|
+
it "determines session only from a cookie by default" do
|
69
|
+
pool = Rack::Session::Redis.new(incrementor)
|
70
|
+
req = Rack::MockRequest.new(pool)
|
71
|
+
res = req.get("/")
|
72
|
+
sid = res["Set-Cookie"][session_match, 1]
|
73
|
+
req.get("/?rack.session=#{sid}").
|
74
|
+
body.must_equal('{"counter"=>1}')
|
75
|
+
req.get("/?rack.session=#{sid}").
|
76
|
+
body.must_equal('{"counter"=>1}')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "determines session from params" do
|
80
|
+
pool = Rack::Session::Redis.new(incrementor, :cookie_only => false)
|
81
|
+
req = Rack::MockRequest.new(pool)
|
82
|
+
res = req.get("/")
|
83
|
+
sid = res["Set-Cookie"][session_match, 1]
|
84
|
+
req.get("/?rack.session=#{sid}").
|
85
|
+
body.must_equal('{"counter"=>2}')
|
86
|
+
req.get("/?rack.session=#{sid}").
|
87
|
+
body.must_equal('{"counter"=>3}')
|
88
|
+
end
|
89
|
+
|
90
|
+
it "survives nonexistant cookies" do
|
91
|
+
bad_cookie = "rack.session=blarghfasel"
|
92
|
+
pool = Rack::Session::Redis.new(incrementor)
|
93
|
+
res = Rack::MockRequest.new(pool).
|
94
|
+
get("/", "HTTP_COOKIE" => bad_cookie)
|
95
|
+
res.body.must_equal('{"counter"=>1}')
|
96
|
+
cookie = res["Set-Cookie"][session_match]
|
97
|
+
cookie.wont_match(/#{bad_cookie}/)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "maintains freshness" do
|
101
|
+
pool = Rack::Session::Redis.new(incrementor, :expire_after => 3)
|
102
|
+
res = Rack::MockRequest.new(pool).get('/')
|
103
|
+
res.body.must_include('"counter"=>1')
|
104
|
+
cookie = res["Set-Cookie"]
|
105
|
+
sid = cookie[session_match, 1]
|
106
|
+
res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
|
107
|
+
res["Set-Cookie"][session_match, 1].must_equal(sid)
|
108
|
+
res.body.must_include('"counter"=>2')
|
109
|
+
puts 'Sleeping to expire session' if $DEBUG
|
110
|
+
sleep 4
|
111
|
+
res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
|
112
|
+
res["Set-Cookie"][session_match, 1].wont_equal(sid)
|
113
|
+
res.body.must_include('"counter"=>1')
|
114
|
+
end
|
115
|
+
|
116
|
+
it "does not send the same session id if it did not change" do
|
117
|
+
pool = Rack::Session::Redis.new(incrementor)
|
118
|
+
req = Rack::MockRequest.new(pool)
|
119
|
+
|
120
|
+
res0 = req.get("/")
|
121
|
+
cookie = res0["Set-Cookie"]
|
122
|
+
res0.body.must_equal('{"counter"=>1}')
|
123
|
+
|
124
|
+
res1 = req.get("/", "HTTP_COOKIE" => cookie)
|
125
|
+
res1["Set-Cookie"].must_be_nil
|
126
|
+
res1.body.must_equal('{"counter"=>2}')
|
127
|
+
|
128
|
+
res2 = req.get("/", "HTTP_COOKIE" => cookie)
|
129
|
+
res2["Set-Cookie"].must_be_nil
|
130
|
+
res2.body.must_equal('{"counter"=>3}')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "deletes cookies with :drop option" do
|
134
|
+
pool = Rack::Session::Redis.new(incrementor)
|
135
|
+
req = Rack::MockRequest.new(pool)
|
136
|
+
drop = Rack::Utils::Context.new(pool, drop_session)
|
137
|
+
dreq = Rack::MockRequest.new(drop)
|
138
|
+
|
139
|
+
res1 = req.get("/")
|
140
|
+
session = (cookie = res1["Set-Cookie"])[session_match]
|
141
|
+
res1.body.must_equal('{"counter"=>1}')
|
142
|
+
|
143
|
+
res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
|
144
|
+
res2["Set-Cookie"].must_be_nil
|
145
|
+
res2.body.must_equal('{"counter"=>2}')
|
146
|
+
|
147
|
+
res3 = req.get("/", "HTTP_COOKIE" => cookie)
|
148
|
+
res3["Set-Cookie"][session_match].wont_equal(session)
|
149
|
+
res3.body.must_equal('{"counter"=>1}')
|
150
|
+
end
|
151
|
+
|
152
|
+
it "provides new session id with :renew option" do
|
153
|
+
pool = Rack::Session::Redis.new(incrementor)
|
154
|
+
req = Rack::MockRequest.new(pool)
|
155
|
+
renew = Rack::Utils::Context.new(pool, renew_session)
|
156
|
+
rreq = Rack::MockRequest.new(renew)
|
157
|
+
|
158
|
+
res1 = req.get("/")
|
159
|
+
session = (cookie = res1["Set-Cookie"])[session_match]
|
160
|
+
res1.body.must_equal('{"counter"=>1}')
|
161
|
+
|
162
|
+
res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
|
163
|
+
new_cookie = res2["Set-Cookie"]
|
164
|
+
new_session = new_cookie[session_match]
|
165
|
+
new_session.wont_equal(session)
|
166
|
+
res2.body.must_equal('{"counter"=>2}')
|
167
|
+
|
168
|
+
res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
|
169
|
+
res3.body.must_equal('{"counter"=>3}')
|
170
|
+
|
171
|
+
# Old cookie was deleted
|
172
|
+
res4 = req.get("/", "HTTP_COOKIE" => cookie)
|
173
|
+
res4.body.must_equal('{"counter"=>1}')
|
174
|
+
end
|
175
|
+
|
176
|
+
it "omits cookie with :defer option" do
|
177
|
+
pool = Rack::Session::Redis.new(incrementor)
|
178
|
+
defer = Rack::Utils::Context.new(pool, defer_session)
|
179
|
+
dreq = Rack::MockRequest.new(defer)
|
180
|
+
|
181
|
+
res0 = dreq.get("/")
|
182
|
+
res0["Set-Cookie"].must_be_nil
|
183
|
+
res0.body.must_equal('{"counter"=>1}')
|
184
|
+
end
|
185
|
+
|
186
|
+
it "updates deep hashes correctly" do
|
187
|
+
hash_check = proc do |env|
|
188
|
+
session = env['rack.session']
|
189
|
+
unless session.include? 'test'
|
190
|
+
session.update :a => :b, :c => { :d => :e },
|
191
|
+
:f => { :g => { :h => :i} }, 'test' => true
|
192
|
+
else
|
193
|
+
session[:f][:g][:h] = :j
|
194
|
+
end
|
195
|
+
[200, {}, [session.inspect]]
|
196
|
+
end
|
197
|
+
pool = Rack::Session::Redis.new(hash_check)
|
198
|
+
req = Rack::MockRequest.new(pool)
|
199
|
+
|
200
|
+
res0 = req.get("/")
|
201
|
+
session_id = (cookie = res0["Set-Cookie"])[session_match, 1]
|
202
|
+
ses0 = pool.pool.get(session_id)
|
203
|
+
|
204
|
+
req.get("/", "HTTP_COOKIE" => cookie)
|
205
|
+
ses1 = pool.pool.get(session_id)
|
206
|
+
|
207
|
+
ses1.wont_equal(ses0)
|
208
|
+
end
|
209
|
+
|
210
|
+
# anyone know how to do this better?
|
211
|
+
it "cleanly merges sessions when multithreaded" do
|
212
|
+
unless $DEBUG
|
213
|
+
1.must_equal(1) # fake assertion to appease the mighty bacon
|
214
|
+
next
|
215
|
+
end
|
216
|
+
warn 'Running multithread test for Session::Redis'
|
217
|
+
pool = Rack::Session::Redis.new(incrementor)
|
218
|
+
req = Rack::MockRequest.new(pool)
|
219
|
+
|
220
|
+
res = req.get('/')
|
221
|
+
res.body.must_equal('{"counter"=>1}')
|
222
|
+
cookie = res["Set-Cookie"]
|
223
|
+
session_id = cookie[session_match, 1]
|
224
|
+
|
225
|
+
delta_incrementor = lambda do |env|
|
226
|
+
# emulate disconjoinment of threading
|
227
|
+
env['rack.session'] = env['rack.session'].dup
|
228
|
+
Thread.stop
|
229
|
+
env['rack.session'][(Time.now.usec*rand).to_i] = true
|
230
|
+
incrementor.call(env)
|
231
|
+
end
|
232
|
+
tses = Rack::Utils::Context.new pool, delta_incrementor
|
233
|
+
treq = Rack::MockRequest.new(tses)
|
234
|
+
tnum = rand(7).to_i+5
|
235
|
+
r = Array.new(tnum) do
|
236
|
+
Thread.new(treq) do |run|
|
237
|
+
run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true)
|
238
|
+
end
|
239
|
+
end.reverse.map{|t| t.run.join.value }
|
240
|
+
r.each do |request|
|
241
|
+
request['Set-Cookie'].must_equal(cookie)
|
242
|
+
request.body.must_include('"counter"=>2')
|
243
|
+
end
|
244
|
+
|
245
|
+
session = pool.pool.get(session_id)
|
246
|
+
session.size.must_equal(tnum+1) # counter
|
247
|
+
session['counter'].must_equal(2) # meeeh
|
248
|
+
|
249
|
+
tnum = rand(7).to_i+5
|
250
|
+
r = Array.new(tnum) do |i|
|
251
|
+
app = Rack::Utils::Context.new pool, time_delta
|
252
|
+
req = Rack::MockRequest.new app
|
253
|
+
Thread.new(req) do |run|
|
254
|
+
run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true)
|
255
|
+
end
|
256
|
+
end.reverse.map{|t| t.run.join.value }
|
257
|
+
r.each do |request|
|
258
|
+
request['Set-Cookie'].must_equal(cookie)
|
259
|
+
request.body.must_include('"counter"=>3')
|
260
|
+
end
|
261
|
+
|
262
|
+
session = pool.pool.get(session_id)
|
263
|
+
session.size.must_equal(tnum+1)
|
264
|
+
session['counter'].must_equal(3)
|
265
|
+
|
266
|
+
drop_counter = proc do |env|
|
267
|
+
env['rack.session'].delete 'counter'
|
268
|
+
env['rack.session']['foo'] = 'bar'
|
269
|
+
[200, {'Content-Type'=>'text/plain'}, env['rack.session'].inspect]
|
270
|
+
end
|
271
|
+
tses = Rack::Utils::Context.new pool, drop_counter
|
272
|
+
treq = Rack::MockRequest.new(tses)
|
273
|
+
tnum = rand(7).to_i+5
|
274
|
+
r = Array.new(tnum) do
|
275
|
+
Thread.new(treq) do |run|
|
276
|
+
run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true)
|
277
|
+
end
|
278
|
+
end.reverse.map{|t| t.run.join.value }
|
279
|
+
r.each do |request|
|
280
|
+
request['Set-Cookie'].must_equal(cookie)
|
281
|
+
request.body.must_include('"foo"=>"bar"')
|
282
|
+
end
|
283
|
+
|
284
|
+
session = pool.pool.get(session_id)
|
285
|
+
session.size.must_equal(r.size+1)
|
286
|
+
session['counter'].must_be_nil
|
287
|
+
session['foo'].must_equal('bar')
|
288
|
+
end
|
289
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,71 +1,137 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-rack
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 0.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.5.rc
|
5
|
+
prerelease: 6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Luca Guidi
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
date: 2012-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis-store
|
16
|
+
requirement: &70299850116400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.0.rc2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70299850116400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
requirement: &70299850115460 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.5
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70299850115460
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &70299850114340 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.9.2.2
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70299850114340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &70299850113420 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.rc
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70299850113420
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mocha
|
60
|
+
requirement: &70299850112500 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.10.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70299850112500
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: &70299850111040 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.8.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70299850111040
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: purdytest
|
82
|
+
requirement: &70299850110420 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.0.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70299850110420
|
91
|
+
description: Redis Store for Rack
|
92
|
+
email:
|
23
93
|
- guidi.luca@gmail.com
|
24
94
|
executables: []
|
25
|
-
|
26
95
|
extensions: []
|
27
|
-
|
28
96
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
97
|
+
files:
|
31
98
|
- .gitignore
|
32
99
|
- Gemfile
|
100
|
+
- MIT-LICENSE
|
101
|
+
- README.md
|
33
102
|
- Rakefile
|
103
|
+
- lib/rack/session/redis.rb
|
34
104
|
- lib/redis-rack.rb
|
35
|
-
- lib/redis
|
105
|
+
- lib/redis/rack/version.rb
|
36
106
|
- redis-rack.gemspec
|
107
|
+
- test/rack/session/redis_test.rb
|
108
|
+
- test/redis/rack/version_test.rb
|
109
|
+
- test/test_helper.rb
|
37
110
|
homepage: http://jodosha.github.com/redis-store
|
38
111
|
licenses: []
|
39
|
-
|
40
112
|
post_install_message:
|
41
113
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
114
|
+
require_paths:
|
44
115
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
117
|
none: false
|
47
|
-
requirements:
|
48
|
-
- -
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
|
51
|
-
|
52
|
-
- 0
|
53
|
-
version: "0"
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
123
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
version: "0"
|
124
|
+
requirements:
|
125
|
+
- - ! '>'
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.3.1
|
63
128
|
requirements: []
|
64
|
-
|
65
129
|
rubyforge_project: redis-rack
|
66
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.15
|
67
131
|
signing_key:
|
68
132
|
specification_version: 3
|
69
|
-
summary: Redis for Rack
|
70
|
-
test_files:
|
71
|
-
|
133
|
+
summary: Redis Store for Rack
|
134
|
+
test_files:
|
135
|
+
- test/rack/session/redis_test.rb
|
136
|
+
- test/redis/rack/version_test.rb
|
137
|
+
- test/test_helper.rb
|