rack-redic 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43484c06c532c0e7c89c6f54a707b8ad8e00ee27
4
- data.tar.gz: 7cba588e68fb54635a9e87533922aec5545ae1b0
3
+ metadata.gz: f2ec8fd6b79b193d9477a2a3e505c2e8b1a9d508
4
+ data.tar.gz: 1fb65c75df68f18697e0112ea8a33ada78c7cdf1
5
5
  SHA512:
6
- metadata.gz: 927b0fe62ecd72c3730dd4d68f05aacdec5dd80435b33368c4933bb283eee2e3f41dcdb1b13309120935f3632873b22fad48b2c17c4062046cf942917785d8d1
7
- data.tar.gz: 5a076b28ae7ce33cc0b9b1bef0982a456b379c5cd70eb75e6ee4296fdaa5b15e26a63480a65516cc0eb472161b92a2058a773c0aafd3f32b7e9c5f241835c5cc
6
+ metadata.gz: 6145a1638dd901fe0f9583a1a97625e40d3cf7a527dc160af396e4a594c1902c0946c1d7ffd6d8df224c0a5132971c117ee8299b316ac694636f5f6e1a41a3ef
7
+ data.tar.gz: 62c3e516605e0b582f8e959e865685958f4439feaa157a2cf879605e8581ccf23e1c6cef6345b0cab54f5f4b0dd4c8602f5a3a9907dd178b4764c707cc15908d
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Rack::Session::Redic provides simple cookie based session management. Session data is stored in Redis via the [Redic](https://github.com/amakawa/redic) gem. The corresponding session key is maintained in the cookie.
4
4
 
5
+ Options include:
6
+
7
+ - `:marshaller` - You may optionally supply the class/module you would like to use when marshalling objects in and out of Redis. All that is required is that this class respond to the `load` and `dump` methods, returning the session hash and a string respectively.
8
+ - `:url` - Addtionally, you may pass in the URL for your Redis server. The default URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku and others' practices.
9
+ - `:expire_after` - Finally, expiration will be passed to the Redis server via the 'EX' option on 'SET'. Expiration should be in seconds, just like Rack's default handling of the `:expire_after` option. This option will refresh the expiration set in Redis with each request.
10
+
5
11
  You may optionally supply the class/module you would like to use when marshalling objects in and out of Redis. All that is required is that this class respond to the `load` and `dump` methods, returning the session hash and a string respectively.
6
12
 
7
13
  Addtionally, you may pass in the URL for your Redis server. The default URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku and others' practices.
@@ -39,6 +45,9 @@ use Rack::Session::Redic, marshaller: Oj
39
45
 
40
46
  # And/or pass in the URL of your Redis server.
41
47
  use Rack::Session::Redic, marshaller: Oj, url: 'redis://host'
48
+
49
+ # And/or pass in the expiration. (1_800 is 30 minutes in seconds)
50
+ use Rack::Session::Redic, marshaller: Oj, url: 'redis://host', expire_after: 1_800
42
51
  ```
43
52
 
44
53
 
@@ -11,14 +11,19 @@ module Rack
11
11
  # Session data is stored in Redis via the Redic gem. The corresponding
12
12
  # session key is maintained in the cookie.
13
13
  #
14
- # You may optionally supply the class/module you would like to use when
15
- # marshalling objects in and out of Redis. All that is required is that
16
- # this class respond to the `load` and `dump` methods, returning the
17
- # session hash and a string respectively.
14
+ # Options include:
18
15
  #
19
- # Addtionally, you may pass in the URL for your Redis server. The default
20
- # URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku and
21
- # others' practices.
16
+ # - :marshaller - You may optionally supply the class/module you would
17
+ # like to use when marshalling objects in and out of Redis. All that is
18
+ # required is that this class respond to the `load` and `dump` methods,
19
+ # returning the session hash and a string respectively.
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.
23
+ # - :expire_after - Finally, expiration will be passed to the Redis server
24
+ # via the 'EX' option on 'SET'. Expiration should be in seconds, just like
25
+ # Rack's default handling of the :expire_after option. This option will
26
+ # refresh the expiration set in Redis with each request.
22
27
  #
23
28
  # Any other options will get passed to Rack::Session::Abstract::Persisted.
24
29
  #
@@ -28,7 +33,7 @@ module Rack
28
33
 
29
34
  @mutex = Mutex.new
30
35
  @marshaller = options.delete(:marshaller) { Marshal }
31
- @storage = StorageWrapper.new(@marshaller, options.delete(:url) { ENV.fetch('REDIS_URL') })
36
+ @storage = StorageWrapper.new(@marshaller, options.delete(:url) { ENV.fetch('REDIS_URL') }, options[:expire_after])
32
37
  end
33
38
 
34
39
  # Only accept a generated session ID if it doesn't exist.
@@ -78,7 +83,8 @@ module Rack
78
83
  GET = 'GET'
79
84
  SET = 'SET'
80
85
 
81
- def initialize(marshaller, url)
86
+ def initialize(marshaller, url, expires)
87
+ @expires = expires
82
88
  @marshaller = marshaller
83
89
  @storage = ::Redic.new(url)
84
90
  end
@@ -92,7 +98,10 @@ module Rack
92
98
  end
93
99
 
94
100
  def set(id, object)
95
- @storage.call(SET, id, serialize(object))
101
+ arguments = [SET, id, serialize(object)]
102
+ arguments = arguments + ['EX', @expires] if @expires
103
+
104
+ @storage.call(*arguments)
96
105
  end
97
106
 
98
107
  def delete(id)
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.1.0'
5
+ spec.version = '0.2.0'
6
6
  spec.authors = ['Evan Lecklider']
7
7
  spec.email = ['evan@lecklider.com']
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-redic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Lecklider