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 +4 -4
- data/README.md +9 -0
- data/lib/rack/session/redic.rb +19 -10
- data/rack-redic.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2ec8fd6b79b193d9477a2a3e505c2e8b1a9d508
|
4
|
+
data.tar.gz: 1fb65c75df68f18697e0112ea8a33ada78c7cdf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/rack/session/redic.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
#
|
20
|
-
#
|
21
|
-
#
|
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
|
-
|
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