rack-redis-session-store 1.0.1 → 1.1.0

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 CHANGED
@@ -15,3 +15,6 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
19
+ *.iml
20
+
@@ -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::Wrapper.new(:size => options[:max_connections], :timeout => 5) {
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
- loop do
18
- sid = super
19
- break sid unless @redis.get(sid)
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
- unless sid and session = @redis.get(sid)
25
- sid, session = generate_sid, {}
26
- unless /^OK/ =~ @redis.set(sid, session.to_json)
27
- raise "Session collision on '#{sid.inspect}'"
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
- session = JSON.parse(session)
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
- @redis.set session_id, new_session.to_json
37
- session_id
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
- @redis.del(session_id)
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'
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.1
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-03-12 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler