rack-redis-session-store 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/lib/rack-redis-session-store.rb +27 -12
- data/lib/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
@@ -7,38 +7,53 @@ module ActionDispatch
|
|
7
7
|
module Session
|
8
8
|
class RedisStore < Rack::Session::Abstract::ID
|
9
9
|
def initialize(app, options = {})
|
10
|
-
@redis = ConnectionPool
|
10
|
+
@redis = ConnectionPool.new(:size => options[:max_connections], :timeout => 5) {
|
11
11
|
Redis.new(:host => "#{options[:host]}", :port => options[:port], db: options[:db])
|
12
12
|
}
|
13
|
+
options[:expire_after] ||= 1.day.to_i
|
13
14
|
super
|
14
15
|
end
|
15
16
|
|
16
17
|
def generate_sid
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
@redis.with do |redis|
|
19
|
+
loop do
|
20
|
+
sid = super
|
21
|
+
break sid unless redis.get(sid)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
def get_session(env, sid)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
session = {}
|
28
|
+
if sid!='null'
|
29
|
+
@redis.with do |redis|
|
30
|
+
options = env['rack.session.options']
|
31
|
+
session_string = redis.get(sid)
|
32
|
+
if session_string
|
33
|
+
session = JSON.parse(session_string)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
else
|
30
|
-
|
37
|
+
sid = generate_sid
|
31
38
|
end
|
32
39
|
[sid, session]
|
33
40
|
end
|
34
41
|
|
35
42
|
def set_session(env, session_id, new_session, options)
|
36
|
-
|
37
|
-
|
43
|
+
if (!new_session.empty?)
|
44
|
+
@redis.with do |redis|
|
45
|
+
redis.setex session_id, options[:expire_after], new_session.to_json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
#For some reason, rack doesn't set new session_id to options[:id]
|
49
|
+
options[:id] = session_id
|
38
50
|
end
|
39
51
|
|
40
52
|
def destroy_session(env, session_id, options)
|
41
|
-
|
53
|
+
puts('Destroy session')
|
54
|
+
@redis.with do |redis|
|
55
|
+
redis.del(session_id)
|
56
|
+
end
|
42
57
|
generate_sid unless options[:drop]
|
43
58
|
end
|
44
59
|
end
|
data/lib/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = '1.0
|
1
|
+
VERSION = '1.1.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-redis-session-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|