angus-authentication 0.0.3 → 0.0.4
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.
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'connection_pool'
|
1
2
|
require 'json'
|
2
3
|
require 'redis'
|
3
4
|
|
@@ -7,28 +8,40 @@ module Angus
|
|
7
8
|
class RedisStore
|
8
9
|
|
9
10
|
DEFAULT_NAMESPACE = ''
|
11
|
+
REDIS_POOL_SIZE = 10
|
12
|
+
REDIS_POOL_TIMEOUT = 5
|
10
13
|
|
11
14
|
def initialize(settings)
|
12
15
|
settings = settings.dup
|
13
16
|
@namespace = settings.delete(:namespace) || DEFAULT_NAMESPACE
|
17
|
+
@pool_size = settings.delete(:pool_size) || REDIS_POOL_SIZE
|
18
|
+
@pool_timeout = settings.delete(:pool_timeout) || REDIS_POOL_TIMEOUT
|
14
19
|
@settings = settings
|
15
20
|
end
|
16
21
|
|
17
22
|
def has_key?(key)
|
18
|
-
redis.exists(add_namespace(key))
|
23
|
+
redis.with { |connection| connection.exists(add_namespace(key)) }
|
19
24
|
end
|
20
25
|
|
21
26
|
def save_session_data(key, data, ttl)
|
22
|
-
redis.
|
23
|
-
|
27
|
+
redis.with do |connection|
|
28
|
+
connection.set(add_namespace(key), JSON(data))
|
29
|
+
connection.expire(add_namespace(key), ttl)
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
def get_session_data(key)
|
27
|
-
|
34
|
+
data = redis.with { |connection| connection.get(add_namespace(key)) } || '{}'
|
35
|
+
JSON(data)
|
28
36
|
end
|
29
37
|
|
30
38
|
def redis
|
31
|
-
@redis ||= Redis.new(@settings)
|
39
|
+
@redis ||= ConnectionPool.new(pool_settings) { Redis.new(@settings) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def pool_settings
|
43
|
+
{ :size => @pool_size,
|
44
|
+
:timeout => @pool_timeout }
|
32
45
|
end
|
33
46
|
|
34
47
|
def add_namespace(key)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angus-authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: connection_pool
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.2'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.2'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rake
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|