redis-rack 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +8 -7
- data/lib/rack/session/redis.rb +24 -15
- data/lib/redis/rack/version.rb +1 -2
- data/redis-rack.gemspec +2 -4
- data/test/rack/session/redis_test.rb +14 -8
- metadata +15 -11
- data/Appraisals +0 -7
- data/gemfiles/rack_1.gemfile +0 -7
- data/gemfiles/rack_2.gemfile +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd358598a3b5173b0af0e6af5a0eb8544d33beb746a24c0d4ae01cb01e5e82c1
|
4
|
+
data.tar.gz: 9afa606f06fc3a5b6812ac5d5a961bc440df74b2ac27160a03536fa0f69d7474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a88c2a36dca22320e1e8d015fbfd0ece8b71f814c60e7a90cb1036ae8cee9f713f3321389f286c707b982a5a82c8b5078ffe93b58c37e17367fec6aa8544e209
|
7
|
+
data.tar.gz: 41722398d1973c7390155fb71c9fe17e3e99e1b0093db1b7d588c77dec01487390b4208a8e04ff0a8050d0f03029c606d619e68da7cbfed9e3bdf397159c0502
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.2
|
data/.travis.yml
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
script: bundle exec rake
|
3
3
|
rvm:
|
4
|
-
- 2.2
|
5
|
-
- 2.3
|
6
|
-
-
|
7
|
-
-
|
4
|
+
- 2.2
|
5
|
+
- 2.3
|
6
|
+
- 2.4
|
7
|
+
- 2.5
|
8
|
+
- 2.6
|
9
|
+
- 2.7
|
10
|
+
- ruby-head
|
11
|
+
- jruby-head
|
8
12
|
matrix:
|
9
13
|
allow_failures:
|
10
14
|
- rvm: jruby-head
|
11
15
|
- rvm: ruby-head
|
12
|
-
gemfile:
|
13
|
-
- gemfiles/rack_2.gemfile
|
14
|
-
- gemfiles/rack_1.gemfile
|
15
16
|
deploy:
|
16
17
|
provider: rubygems
|
17
18
|
api_key:
|
data/lib/rack/session/redis.rb
CHANGED
@@ -5,7 +5,7 @@ require 'redis/rack/connection'
|
|
5
5
|
|
6
6
|
module Rack
|
7
7
|
module Session
|
8
|
-
class Redis < Abstract::
|
8
|
+
class Redis < Abstract::PersistedSecure
|
9
9
|
attr_reader :mutex
|
10
10
|
|
11
11
|
DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge(
|
@@ -24,18 +24,18 @@ module Rack
|
|
24
24
|
loop do
|
25
25
|
sid = generate_sid
|
26
26
|
first = with do |c|
|
27
|
-
[*c.setnx(sid, session, @default_options)].first
|
27
|
+
[*c.setnx(sid.private_id, session, @default_options)].first
|
28
28
|
end
|
29
29
|
break sid if [1, true].include?(first)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
if
|
33
|
+
def find_session(req, sid)
|
34
|
+
if req.session.options[:skip]
|
35
35
|
[generate_sid, {}]
|
36
36
|
else
|
37
|
-
with_lock(
|
38
|
-
unless sid and session =
|
37
|
+
with_lock(req, [nil, {}]) do
|
38
|
+
unless sid and session = get_session_with_fallback(sid)
|
39
39
|
session = {}
|
40
40
|
sid = generate_unique_sid(session)
|
41
41
|
end
|
@@ -44,16 +44,19 @@ module Rack
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
with_lock(
|
49
|
-
with { |c| c.set
|
50
|
-
|
47
|
+
def write_session(req, sid, new_session, options)
|
48
|
+
with_lock(req, false) do
|
49
|
+
with { |c| c.set sid.private_id, new_session, options }
|
50
|
+
sid
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
with_lock(
|
56
|
-
with
|
54
|
+
def delete_session(req, sid, options)
|
55
|
+
with_lock(req) do
|
56
|
+
with do |c|
|
57
|
+
c.del(sid.public_id)
|
58
|
+
c.del(sid.private_id)
|
59
|
+
end
|
57
60
|
generate_sid unless options[:drop]
|
58
61
|
end
|
59
62
|
end
|
@@ -62,8 +65,8 @@ module Rack
|
|
62
65
|
@default_options.fetch(:threadsafe, true)
|
63
66
|
end
|
64
67
|
|
65
|
-
def with_lock(
|
66
|
-
@mutex.lock if
|
68
|
+
def with_lock(req, default=nil)
|
69
|
+
@mutex.lock if req.multithread? && threadsafe?
|
67
70
|
yield
|
68
71
|
rescue Errno::ECONNREFUSED
|
69
72
|
if $VERBOSE
|
@@ -78,6 +81,12 @@ module Rack
|
|
78
81
|
def with(&block)
|
79
82
|
@conn.with(&block)
|
80
83
|
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def get_session_with_fallback(sid)
|
88
|
+
with { |c| c.get(sid.private_id) || c.get(sid.public_id) }
|
89
|
+
end
|
81
90
|
end
|
82
91
|
end
|
83
92
|
end
|
data/lib/redis/rack/version.rb
CHANGED
data/redis-rack.gemspec
CHANGED
@@ -12,18 +12,16 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = %q{Redis Store for Rack applications}
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
|
-
s.rubyforge_project = 'redis-rack'
|
16
|
-
|
17
15
|
s.files = `git ls-files`.split("\n")
|
18
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
17
|
s.executables = []
|
20
18
|
s.require_paths = ["lib"]
|
21
19
|
|
22
20
|
s.add_runtime_dependency 'redis-store', ['< 2', '>= 1.2']
|
23
|
-
s.add_runtime_dependency 'rack', '>=
|
21
|
+
s.add_runtime_dependency 'rack', '>= 2.0.8', '< 3'
|
24
22
|
|
25
23
|
s.add_development_dependency 'rake', '~> 10'
|
26
|
-
s.add_development_dependency 'bundler', '
|
24
|
+
s.add_development_dependency 'bundler', '> 1', '< 3'
|
27
25
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
28
26
|
s.add_development_dependency 'minitest', '~> 5'
|
29
27
|
s.add_development_dependency 'redis-store-testing'
|
@@ -93,7 +93,7 @@ describe Rack::Session::Redis do
|
|
93
93
|
it "does not store a blank session" do
|
94
94
|
session_store = Rack::Session::Redis.new(incrementor)
|
95
95
|
sid = session_store.generate_unique_sid({})
|
96
|
-
session_store.with { |c| c.get(sid).must_be_nil }
|
96
|
+
session_store.with { |c| c.get(sid.private_id).must_be_nil }
|
97
97
|
end
|
98
98
|
|
99
99
|
it "locks the store mutex" do
|
@@ -102,7 +102,9 @@ describe Rack::Session::Redis do
|
|
102
102
|
sesion_store = Rack::Session::Redis.new(incrementor)
|
103
103
|
sesion_store.instance_variable_set(:@mutex, mutex)
|
104
104
|
was_yielded = false
|
105
|
-
|
105
|
+
request = Minitest::Mock.new
|
106
|
+
request.expect(:multithread?, true)
|
107
|
+
sesion_store.with_lock(request) { was_yielded = true}
|
106
108
|
was_yielded.must_equal(true)
|
107
109
|
end
|
108
110
|
|
@@ -118,7 +120,9 @@ describe Rack::Session::Redis do
|
|
118
120
|
sesion_store = Rack::Session::Redis.new(incrementor, :threadsafe => false)
|
119
121
|
sesion_store.instance_variable_set(:@mutex, mutex)
|
120
122
|
was_yielded = false
|
121
|
-
|
123
|
+
request = Minitest::Mock.new
|
124
|
+
request.expect(:multithread?, true)
|
125
|
+
sesion_store.with_lock(request) { was_yielded = true}
|
122
126
|
was_yielded.must_equal(true)
|
123
127
|
end
|
124
128
|
end
|
@@ -295,10 +299,11 @@ describe Rack::Session::Redis do
|
|
295
299
|
|
296
300
|
res0 = req.get("/")
|
297
301
|
session_id = (cookie = res0["Set-Cookie"])[session_match, 1]
|
298
|
-
|
302
|
+
sid = Rack::Session::SessionId.new(session_id)
|
303
|
+
ses0 = pool.with { |c| c.get(sid.private_id) }
|
299
304
|
|
300
305
|
req.get("/", "HTTP_COOKIE" => cookie)
|
301
|
-
ses1 = pool.with { |c| c.get(
|
306
|
+
ses1 = pool.with { |c| c.get(sid.private_id) }
|
302
307
|
|
303
308
|
ses1.wont_equal(ses0)
|
304
309
|
end
|
@@ -318,6 +323,7 @@ describe Rack::Session::Redis do
|
|
318
323
|
res.body.must_equal('{"counter"=>1}')
|
319
324
|
cookie = res["Set-Cookie"]
|
320
325
|
session_id = cookie[session_match, 1]
|
326
|
+
sid = Rack::Session::SessionId.new(session_id)
|
321
327
|
|
322
328
|
delta_incrementor = lambda do |env|
|
323
329
|
# emulate disconjoinment of threading
|
@@ -339,7 +345,7 @@ describe Rack::Session::Redis do
|
|
339
345
|
request.body.must_include('"counter"=>2')
|
340
346
|
end
|
341
347
|
|
342
|
-
session = pool.with { |c| c.get(
|
348
|
+
session = pool.with { |c| c.get(sid.private_id) }
|
343
349
|
session.size.must_equal(tnum+1) # counter
|
344
350
|
session['counter'].must_equal(2) # meeeh
|
345
351
|
|
@@ -356,7 +362,7 @@ describe Rack::Session::Redis do
|
|
356
362
|
request.body.must_include('"counter"=>3')
|
357
363
|
end
|
358
364
|
|
359
|
-
session = pool.with { |c| c.get(
|
365
|
+
session = pool.with { |c| c.get(sid.private_id) }
|
360
366
|
session.size.must_equal(tnum+1)
|
361
367
|
session['counter'].must_equal(3)
|
362
368
|
|
@@ -378,7 +384,7 @@ describe Rack::Session::Redis do
|
|
378
384
|
request.body.must_include('"foo"=>"bar"')
|
379
385
|
end
|
380
386
|
|
381
|
-
session = pool.with { |c| c.get(
|
387
|
+
session = pool.with { |c| c.get(sid.private_id) }
|
382
388
|
session.size.must_equal(r.size+1)
|
383
389
|
session['counter'].must_be_nil
|
384
390
|
session['foo'].must_equal('bar')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-store
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 2.0.8
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '3'
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
49
|
+
version: 2.0.8
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '3'
|
@@ -68,16 +68,22 @@ dependencies:
|
|
68
68
|
name: bundler
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1'
|
74
|
+
- - "<"
|
72
75
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
76
|
+
version: '3'
|
74
77
|
type: :development
|
75
78
|
prerelease: false
|
76
79
|
version_requirements: !ruby/object:Gem::Requirement
|
77
80
|
requirements:
|
78
|
-
- - "
|
81
|
+
- - ">"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1'
|
84
|
+
- - "<"
|
79
85
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
86
|
+
version: '3'
|
81
87
|
- !ruby/object:Gem::Dependency
|
82
88
|
name: mocha
|
83
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,8 +163,8 @@ extra_rdoc_files: []
|
|
157
163
|
files:
|
158
164
|
- ".github/auto-assign-issues.yml"
|
159
165
|
- ".gitignore"
|
166
|
+
- ".ruby-version"
|
160
167
|
- ".travis.yml"
|
161
|
-
- Appraisals
|
162
168
|
- CODEOWNERS
|
163
169
|
- Gemfile
|
164
170
|
- MIT-LICENSE
|
@@ -166,8 +172,6 @@ files:
|
|
166
172
|
- Rakefile
|
167
173
|
- bin/appraisal
|
168
174
|
- bin/rake
|
169
|
-
- gemfiles/rack_1.gemfile
|
170
|
-
- gemfiles/rack_2.gemfile
|
171
175
|
- lib/rack/session/redis.rb
|
172
176
|
- lib/redis-rack.rb
|
173
177
|
- lib/redis/rack/connection.rb
|
data/Appraisals
DELETED
data/gemfiles/rack_1.gemfile
DELETED