rack-redic 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 060c56a771cd80ea2e61cb4abbf91406e8766daa
4
- data.tar.gz: 4f77b38762b713d241ea93a5daf9a70241f4e1f0
3
+ metadata.gz: 3d4afdb628407b7b0dac6cf05ac9ea5d33497bae
4
+ data.tar.gz: 747344ab157680920425f77776de3b7150d2cd9c
5
5
  SHA512:
6
- metadata.gz: 21d1c9430203b82f90daabe32fcbd30050468b2f59c693ec454cbbcf2ff62398a580c86486cb60b7631467e0e7b74dca44e67bc317e20b3458e51b39b6cfface
7
- data.tar.gz: c63d41ef4a89ae67783e12d70a0cd27c82a1a3803af6b3b7127575a398f25a8fe413baac3b365e93c36d64011c12457831f87a53d7df2f18f88e89cc176637b5
6
+ metadata.gz: 7435b1f651cc9952aff451613fc32c6698ef856e3e579b6035d1133d538ba749cbd9ca37fe8cc70f99f68420a1d71b9b9e5d0e16fd6b6d056c3620d8ce331e1b
7
+ data.tar.gz: aae16f6bce3a267b657b4551eb6e3d2b895635319dc9e3b6c21f58f82a778c64b197bd86dd1b51cb5fa29d4e2e5c9a46e560676018f08ac12009a7d072cc0f59
data/Rakefile CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
- task :default => :spec
3
+ task default: :spec
@@ -18,8 +18,8 @@ module Rack
18
18
  # required is that this class respond to the `load` and `dump` methods,
19
19
  # returning the session hash and a string respectively.
20
20
  # - :url - Addtionally, you may pass in the URL for your Redis server. The
21
- # default URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku
22
- # and others' practices.
21
+ # default URL is fetched from the ENV as 'REDIS_URL' in keeping with
22
+ # Heroku and others' practices.
23
23
  # - :expire_after - Finally, expiration will be passed to the Redis server
24
24
  # via the 'EX' option on 'SET'. Expiration should be in seconds, just like
25
25
  # Rack's default handling of the :expire_after option. This option will
@@ -52,10 +52,8 @@ module Rack
52
52
  # Find the session (or generate a blank one).
53
53
  def find_session(_req, sid)
54
54
  @mutex.synchronize do
55
- unless sid and session = @storage.get(sid)
56
- sid, session = generate_sid, {}
57
- @storage.set(sid, session)
58
- end
55
+ sid ||= generate_sid
56
+ session = @storage.get(sid) || @storage.init(sid, {})
59
57
 
60
58
  [sid, session]
61
59
  end
@@ -78,8 +76,7 @@ module Rack
78
76
  end
79
77
  end
80
78
 
81
- private
82
-
79
+ ##
83
80
  # A wrapper around Redic to simplify calls.
84
81
  class Storage
85
82
  # Redis commands.
@@ -103,13 +100,18 @@ module Rack
103
100
  @storage.call(EXISTS, id) != ZERO
104
101
  end
105
102
 
103
+ def init(sid, initial)
104
+ set(sid, initial)
105
+ initial
106
+ end
107
+
106
108
  def get(id)
107
109
  deserialize(@storage.call(GET, id))
108
110
  end
109
111
 
110
112
  def set(id, object)
111
113
  arguments = [SET, id, serialize(object)]
112
- arguments = arguments + [EX, @expires] if @expires
114
+ arguments += [EX, @expires] if @expires
113
115
 
114
116
  @storage.call(*arguments)
115
117
  end
@@ -127,6 +129,7 @@ module Rack
127
129
 
128
130
  # Should always return the session object.
129
131
  def deserialize(string)
132
+ return unless string
130
133
  @marshaller.load(Zlib::Inflate.inflate(string.unpack(PACK).first))
131
134
  end
132
135
  end
data/rack-redic.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rack-redic'
5
- spec.version = '0.3.0'
5
+ spec.version = '0.4.0'
6
6
  spec.authors = ['Evan Lecklider']
7
7
  spec.email = ['evan@lecklider.com']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-redic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Lecklider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-03 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  requirements: []
75
75
  rubyforge_project:
76
- rubygems_version: 2.6.4
76
+ rubygems_version: 2.6.7
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Rack::Session in Redis via Redic