redis-session-store 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: add0c6376d9ff344003c7d062c3844bbe2400037
4
- data.tar.gz: 7cd9506424bad86542695fc97f4072d91703ab0c
3
+ metadata.gz: e8c01a4bd8ba08bf7a390925f4dc40f8b9c008d6
4
+ data.tar.gz: 91efb335e55ba86ee01476a74ab4ed0217b48e85
5
5
  SHA512:
6
- metadata.gz: 0c3cb9bde3e6cc1b979575615b91a19870c4570d3cc2d543f9d38120574f4275df6eab9fdac52779d5a8ec9432e8b95e3f58642c9f1266d27ff442fab915634e
7
- data.tar.gz: 7dc45a9772b50b2b9ee73faa38ea34ae4784f979966d8a034be9a5193c5f34a904f3862563f09894f76bcc172d2534411bc80af6f1ffe795ed453229031a1163
6
+ metadata.gz: cfb8578cfa2a62b70bf4f79ea3574e26c82b5e439d9df7ea3097f6d4bea98543e10590daf2ecc484922feb5868a409af47d5126a768c4f67ba392771837f144f
7
+ data.tar.gz: 1b369cf1663b3ba9a581fc0557541b53546762726086ffa0a799d8fd582a45b4c0b73cfd7ee92f50ec74a90f104155422170ab83007c7f15103daf1a8a712dda
data/.rubocop.yml CHANGED
@@ -1,18 +1 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2014-02-07 09:24:00 -0500 using RuboCop version 0.18.0.
3
- # The point is for the user to remove these configuration records
4
- # one by one as the offences are removed from the code base.
5
- # Note that changes in the inspected code, or installation of new
6
- # versions of RuboCop, may require this file to be generated again.
7
-
8
- Documentation:
9
- Enabled: false
10
-
11
- # Offence count: 6
12
- LineLength:
13
- Max: 124
14
-
15
- # Offence count: 2
16
- # Configuration parameters: CountComments.
17
- MethodLength:
18
- Max: 12
1
+ ---
@@ -3,19 +3,31 @@ require 'redis'
3
3
 
4
4
  # Redis session storage for Rails, and for Rails only. Derived from
5
5
  # the MemCacheStore code, simply dropping in Redis instead.
6
- #
7
- # Options:
8
- # :key => Same as with the other cookie stores, key name
9
- # :redis => {
10
- # :host => Redis host name, default is localhost
11
- # :port => Redis port, default is 6379
12
- # :db => Database number, defaults to 0. Useful to separate your session storage from other data
13
- # :key_prefix => Prefix for keys used in Redis, e.g. myapp-. Useful to separate session storage keys visibly from others
14
- # :expire_after => A number in seconds to set the timeout interval for the session. Will map directly to expiry in Redis
15
- # }
16
6
  class RedisSessionStore < ActionDispatch::Session::AbstractStore
17
- VERSION = '0.3.0'
7
+ VERSION = '0.3.1'
18
8
 
9
+ # ==== Options
10
+ # * +:key+ - Same as with the other cookie stores, key name
11
+ # * +:redis+ - A hash with redis-specific options
12
+ # * +:host+ - Redis host name, default is localhost
13
+ # * +:port+ - Redis port, default is 6379
14
+ # * +:db+ - Database number, defaults to 0.
15
+ # * +:key_prefix+ - Prefix for keys used in Redis, e.g. +myapp:+
16
+ # * +:expire_after+ - A number in seconds for session timeout
17
+ #
18
+ # ==== Examples
19
+ #
20
+ # My::Application.config.session_store = :redis_session_store, {
21
+ # :key => 'your_session_key',
22
+ # :redis => {
23
+ # :db => 2,
24
+ # :expire_after => 120.minutes,
25
+ # :key_prefix => "myapp:session:",
26
+ # :host => 'host', # Redis host name, default is localhost
27
+ # :port => 12345 # Redis port, default is 6379
28
+ # }
29
+ # }
30
+ #
19
31
  def initialize(app, options = {})
20
32
  super
21
33
 
@@ -57,13 +69,19 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
57
69
  return false
58
70
  end
59
71
 
72
+ def destroy_session(env, sid, options)
73
+ redis.del(prefixed(sid))
74
+ generate_sid
75
+ end
76
+
60
77
  def destroy(env)
61
78
  if env['rack.request.cookie_hash'] && env['rack.request.cookie_hash'][key]
62
79
  redis.del(prefixed(env['rack.request.cookie_hash'][key]))
63
80
  end
64
81
  rescue Errno::ECONNREFUSED
65
82
  if defined?(Rails)
66
- Rails.logger.warn('RedisSessionStore#destroy: Connection to redis refused')
83
+ Rails.logger.warn('RedisSessionStore#destroy: ' <<
84
+ 'Connection to redis refused')
67
85
  else
68
86
  warn('RedisSessionStore#destroy: Connection to redis refused')
69
87
  end
@@ -1,12 +1,11 @@
1
1
  # vim:fileencoding=utf-8
2
- require 'English'
3
2
 
4
3
  Gem::Specification.new do |gem|
5
4
  gem.name = 'redis-session-store'
6
5
  gem.authors = ['Mathias Meyer']
7
6
  gem.email = ['meyer@paperplanes.de']
8
7
  gem.summary = 'A drop-in replacement for e.g. MemCacheStore to ' <<
9
- 'store Rails sessions (and Rails sessions only) in Redis.'
8
+ 'store Rails sessions (and Rails sessions only) in Redis.'
10
9
  gem.description = gem.summary
11
10
  gem.homepage = 'https://github.com/roidrage/redis-session-store'
12
11
  gem.license = 'MIT'
@@ -14,8 +13,8 @@ Gem::Specification.new do |gem|
14
13
  gem.has_rdoc = true
15
14
  gem.extra_rdoc_files = %w(LICENSE AUTHORS.md CONTRIBUTING.md)
16
15
 
17
- gem.files = `git ls-files`.split($RS)
18
- gem.require_paths = ['lib']
16
+ gem.files = `git ls-files -z`.split("\x0")
17
+ gem.require_paths = %w(lib)
19
18
  gem.version = File.read('lib/redis-session-store.rb')
20
19
  .match(/^ VERSION = '(.*)'/)[1]
21
20
 
@@ -1,23 +1,31 @@
1
1
  # vim:fileencoding=utf-8
2
2
 
3
3
  unless defined?(ActionDispatch::Session::AbstractStore)
4
- module ActionDispatch
4
+ module ActionDispatch # rubocop:disable Documentation
5
5
  module Session
6
6
  class AbstractStore
7
+ DEFAULT_OPTIONS = {
8
+ key: '_session_id',
9
+ path: '/',
10
+ domain: nil,
11
+ expire_after: nil,
12
+ secure: false,
13
+ httponly: true,
14
+ cookie_only: true
15
+ }.freeze
16
+
7
17
  def initialize(app, options = {})
8
18
  @app = app
9
- @default_options = {
10
- key: '_session_id',
11
- path: '/',
12
- domain: nil,
13
- expire_after: nil,
14
- secure: false,
15
- httponly: true,
16
- cookie_only: true
17
- }.merge(options)
19
+ @default_options = DEFAULT_OPTIONS.dup.merge(options)
18
20
  @key = @default_options[:key]
19
21
  @cookie_only = @default_options[:cookie_only]
20
22
  end
23
+
24
+ private
25
+
26
+ def generate_sid
27
+ rand(999..9999).to_s(16)
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -98,8 +98,9 @@ describe RedisSessionStore do
98
98
  end
99
99
 
100
100
  describe 'rack 1.45 compatibility' do
101
- # Rack 1.45 (which Rails 3.2.x depends on) uses the return value of set_session to set the cookie value
102
- # See https://github.com/rack/rack/blob/1.4.5/lib/rack/session/abstract/id.rb
101
+ # Rack 1.45 (which Rails 3.2.x depends on) uses the return value of
102
+ # set_session to set the cookie value. See:
103
+ # https://github.com/rack/rack/blob/1.4.5/lib/rack/session/abstract/id.rb
103
104
 
104
105
  let(:env) { double('env') }
105
106
  let(:session_id) { 12_345 }
@@ -109,7 +110,8 @@ describe RedisSessionStore do
109
110
  context 'when successfully persisting the session' do
110
111
 
111
112
  it 'returns the session id' do
112
- store.send(:set_session, env, session_id, session_data, options).should eq(session_id)
113
+ store.send(:set_session, env, session_id, session_data, options)
114
+ .should eq(session_id)
113
115
  end
114
116
 
115
117
  end
@@ -120,7 +122,8 @@ describe RedisSessionStore do
120
122
  end
121
123
 
122
124
  it 'returns false' do
123
- store.send(:set_session, env, session_id, session_data, options).should eq(false)
125
+ store.send(:set_session, env, session_id, session_data, options)
126
+ .should eq(false)
124
127
  end
125
128
  end
126
129
 
@@ -147,7 +150,8 @@ describe RedisSessionStore do
147
150
  it 'should return an empty session hash' do
148
151
  store.stub(:redis).and_raise(Errno::ECONNREFUSED)
149
152
 
150
- expect(store.send(:get_session, double('env'), fake_key)).to eq([fake_key, {}])
153
+ expect(store.send(:get_session, double('env'), fake_key))
154
+ .to eq([fake_key, {}])
151
155
  end
152
156
  end
153
157
  end
@@ -162,15 +166,25 @@ describe RedisSessionStore do
162
166
  cookie_hash.stub(:[] => fake_key)
163
167
  end
164
168
 
165
- it 'should delete the prefixed key from redis' do
169
+ it 'deletes the prefixed key from redis' do
166
170
  redis = double('redis')
167
171
  store.stub(redis: redis)
168
- expect(redis).to receive(:del).with("#{options[:key_prefix]}#{fake_key}")
172
+ expect(redis).to receive(:del)
173
+ .with("#{options[:key_prefix]}#{fake_key}")
169
174
 
170
175
  store.send(:destroy, env)
171
176
  end
172
-
173
177
  end
174
178
 
179
+ context 'when destroyed via #destroy_session' do
180
+ it 'deletes the prefixed key from redis' do
181
+ redis = double('redis')
182
+ sid = store.send(:generate_sid)
183
+ store.stub(redis: redis)
184
+ expect(redis).to receive(:del).with("#{options[:key_prefix]}#{sid}")
185
+
186
+ store.send(:destroy_session, {}, sid, nil)
187
+ end
188
+ end
175
189
  end
176
190
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-session-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-13 00:00:00.000000000 Z
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis