redis-session-store 0.4.0 → 0.4.2
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 +4 -4
- data/.rubocop.yml +10 -1
- data/AUTHORS.md +1 -0
- data/README.md +1 -0
- data/lib/redis-session-store.rb +13 -8
- data/spec/redis_session_store_spec.rb +12 -4
- data/spec/support.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56bc245a6348c77dc89fd0f9cafcb190ce55bf0a
|
4
|
+
data.tar.gz: 39c2e4dacfb2bdf3ffdb2ab661199cca1f41bac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c3766b71ff8e0c3d1e1e89497a6cf7e7b59c2cba3a199e7e94f59cd246deb9762df2e3d78fc420cd835cacebfb9eaeeae7cb7809262211fcb4c0aecb7b992a9
|
7
|
+
data.tar.gz: 3dcf04844ab54396592dbae1ac820f600fa73d0147b6695582dc6ae0c4596ab8bedfef2a7c0dc89a4c7c42a73e8a833292a7d11401520c55a5c4737be16ad670
|
data/.rubocop.yml
CHANGED
@@ -1 +1,10 @@
|
|
1
|
-
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-03-13 18:57:37 -0400 using RuboCop version 0.19.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses 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
|
+
# Offense count: 1
|
9
|
+
FileName:
|
10
|
+
Enabled: false
|
data/AUTHORS.md
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@ Redis Session Store
|
|
2
2
|
===================
|
3
3
|
|
4
4
|
[](https://travis-ci.org/roidrage/redis-session-store)
|
5
|
+
[](https://codeclimate.com/github/roidrage/redis-session-store)
|
5
6
|
|
6
7
|
A simple Redis-based session store for Rails. But why, you ask,
|
7
8
|
when there's [redis-store](http://github.com/jodosha/redis-store/)?
|
data/lib/redis-session-store.rb
CHANGED
@@ -4,7 +4,7 @@ require 'redis'
|
|
4
4
|
# Redis session storage for Rails, and for Rails only. Derived from
|
5
5
|
# the MemCacheStore code, simply dropping in Redis instead.
|
6
6
|
class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
7
|
-
VERSION = '0.4.
|
7
|
+
VERSION = '0.4.2'
|
8
8
|
|
9
9
|
# ==== Options
|
10
10
|
# * +:key+ - Same as with the other cookie stores, key name
|
@@ -36,7 +36,7 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
36
36
|
@default_options.merge!(namespace: 'rack:session')
|
37
37
|
@default_options.merge!(redis_options)
|
38
38
|
@redis = Redis.new(redis_options)
|
39
|
-
@raise_errors =
|
39
|
+
@raise_errors = !options[:raise_errors].nil?
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -48,15 +48,20 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def get_session(env, sid)
|
51
|
-
sid
|
52
|
-
|
53
|
-
data = redis.get(prefixed(sid))
|
54
|
-
session = data.nil? ? {} : Marshal.load(data)
|
55
|
-
rescue Errno::ECONNREFUSED => e
|
56
|
-
raise e if raise_errors
|
51
|
+
unless sid && (session = load_session_from_redis(sid))
|
52
|
+
sid = generate_sid
|
57
53
|
session = {}
|
58
54
|
end
|
55
|
+
|
59
56
|
[sid, session]
|
57
|
+
rescue Errno::ECONNREFUSED => e
|
58
|
+
raise e if raise_errors
|
59
|
+
[generate_sid, {}]
|
60
|
+
end
|
61
|
+
|
62
|
+
def load_session_from_redis(sid)
|
63
|
+
data = redis.get(prefixed(sid))
|
64
|
+
data ? Marshal.load(data) : nil
|
60
65
|
end
|
61
66
|
|
62
67
|
def set_session(env, sid, session_data, options = nil)
|
@@ -171,11 +171,19 @@ describe RedisSessionStore do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
context 'when redis is down' do
|
174
|
-
before
|
174
|
+
before do
|
175
|
+
store.stub(:redis).and_raise(Errno::ECONNREFUSED)
|
176
|
+
store.stub(generate_sid: 'foop')
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'returns an empty session hash' do
|
180
|
+
expect(store.send(:get_session, double('env'), fake_key).last)
|
181
|
+
.to eq({})
|
182
|
+
end
|
175
183
|
|
176
|
-
it '
|
177
|
-
expect(store.send(:get_session, double('env'), fake_key))
|
178
|
-
.to eq(
|
184
|
+
it 'returns a newly generated sid' do
|
185
|
+
expect(store.send(:get_session, double('env'), fake_key).first)
|
186
|
+
.to eq('foop')
|
179
187
|
end
|
180
188
|
|
181
189
|
context 'when :raise_errors option is truthy' do
|
data/spec/support.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# vim:fileencoding=utf-8
|
2
2
|
|
3
3
|
unless defined?(ActionDispatch::Session::AbstractStore)
|
4
|
-
module ActionDispatch
|
4
|
+
module ActionDispatch
|
5
5
|
module Session
|
6
|
-
class AbstractStore
|
6
|
+
class AbstractStore # rubocop:disable Documentation
|
7
7
|
ENV_SESSION_OPTIONS_KEY = 'rack.session.options'.freeze
|
8
8
|
DEFAULT_OPTIONS = {
|
9
9
|
key: '_session_id',
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
unless defined?(Rails)
|
36
36
|
require 'logger'
|
37
37
|
|
38
|
-
module Rails
|
38
|
+
module Rails # rubocop:disable Documentation
|
39
39
|
def self.logger
|
40
40
|
@logger ||= Logger.new('/dev/null')
|
41
41
|
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.4.
|
4
|
+
version: 0.4.2
|
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-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|