cache_store_redis 1.0.0 → 2.1.1
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: edb347a21c9194be5a503cd49269450999464c8b6b9e0d76301db09378070877
|
4
|
+
data.tar.gz: 91c4895a3b68615a107401357bb851a2228b7f3fcbe0cf539764bc53e10aff43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3baf73be272515d4a80e2e05dc3adec633187c5066571d7e00efb9087814d442afed6257d213cf67dba855f5f3c3501ab369232c07a3fdabd8397684f4575817
|
7
|
+
data.tar.gz: 3c8363c6745d33f3f782c3ee87cb0d2a54b7bd6c63e5bfc26ebabf92ba91a13e0128d3878fdc724cc53a79cc44ca174723d71591deaf856401b181abe7a2d392
|
data/lib/cache_store_redis.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
# This class is used to define a redis cache store that logs failures as warnings but does not raise errors for
|
4
2
|
# cache connections
|
5
3
|
class OptionalRedisCacheStore
|
@@ -7,7 +5,7 @@ class OptionalRedisCacheStore
|
|
7
5
|
@cache_store = RedisCacheStore.new(namespace, config)
|
8
6
|
@logger = logger || Logger.new(STDOUT)
|
9
7
|
end
|
10
|
-
|
8
|
+
|
11
9
|
def redis_store
|
12
10
|
@cache_store
|
13
11
|
end
|
@@ -39,10 +37,7 @@ class OptionalRedisCacheStore
|
|
39
37
|
def optional_get(key, expires_in = 0)
|
40
38
|
redis_store.get(key, expires_in)
|
41
39
|
rescue => e
|
42
|
-
|
43
|
-
"[#{self.class}] - An error occurred requesting data from the cache. " \
|
44
|
-
"Key: #{key} | Error: #{e.message} | Backtrace: #{e.backtrace}"
|
45
|
-
)
|
40
|
+
handle_error(e, 'requesting data from the cache')
|
46
41
|
nil
|
47
42
|
end
|
48
43
|
|
@@ -60,38 +55,42 @@ class OptionalRedisCacheStore
|
|
60
55
|
def set(key, value, expires_in = 0)
|
61
56
|
redis_store.set(key, value, expires_in)
|
62
57
|
rescue => e
|
63
|
-
|
64
|
-
"[#{self.class}] - An error occurred storing data in the cache. " \
|
65
|
-
"Key: #{key} | Error: #{e.message} | Backtrace: #{e.backtrace}"
|
66
|
-
)
|
58
|
+
handle_error(e, 'storing data in the cache')
|
67
59
|
end
|
68
60
|
|
69
61
|
def remove(key)
|
70
62
|
redis_store.remove(key)
|
71
63
|
rescue => e
|
72
|
-
|
73
|
-
"[#{self.class}] - An error occurred removing data from the cache. " \
|
74
|
-
"Key: #{key} | Error: #{e.message} | Backtrace: #{e.backtrace}"
|
75
|
-
)
|
64
|
+
handle_error(e, 'removing data from the cache')
|
76
65
|
end
|
77
66
|
|
78
67
|
def exist?(key)
|
79
68
|
redis_store.exist?(key)
|
80
69
|
rescue => e
|
81
|
-
|
82
|
-
"[#{self.class}] - An error occurred checking if a key exists in the cache. " \
|
83
|
-
"Key: #{key} | Error: #{e.message} | Backtrace: #{e.backtrace}"
|
84
|
-
)
|
70
|
+
handle_error(e, 'checking if a key exists in the cache')
|
85
71
|
false
|
86
72
|
end
|
87
73
|
|
88
74
|
def ping
|
89
75
|
redis_store.ping
|
90
76
|
rescue => e
|
91
|
-
|
92
|
-
"[#{self.class}] - An error occurred checking pinging the cache. " \
|
93
|
-
"Error: #{e.message} | Backtrace: #{e.backtrace}"
|
94
|
-
)
|
77
|
+
handle_error(e, 'pinging the cache')
|
95
78
|
false
|
96
79
|
end
|
80
|
+
|
81
|
+
def shutdown
|
82
|
+
redis_store.shutdown
|
83
|
+
rescue => e
|
84
|
+
handle_error(e, 'shutting down the connection pool')
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def handle_error(ex, msg)
|
91
|
+
@logger.error do
|
92
|
+
"[#{self.class}] - An error occurred #{msg}. " \
|
93
|
+
"Error: #{ex.message} | Backtrace: #{ex.backtrace}"
|
94
|
+
end
|
95
|
+
end
|
97
96
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
# This class is used to implement a redis cache store.
|
2
2
|
class RedisCacheStore
|
3
|
-
|
4
|
-
|
3
|
+
# Default expiry time if not provided. (1 hour)
|
4
|
+
DEFAULT_TTL = 3_600
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
def initialize(namespace = nil, config = nil)
|
7
|
+
@connection_pool = RedisConnectionPool.new(namespace, config)
|
9
8
|
|
10
9
|
@namespace = namespace
|
11
10
|
@config = config
|
@@ -63,7 +62,7 @@ class RedisCacheStore
|
|
63
62
|
# @param key [String] This is the unique key to reference the value being set within this cache store.
|
64
63
|
# @param value [Object] This is the value to set within this cache store.
|
65
64
|
# @param expires_in [Integer] This is the number of seconds from the current time that this value should expire.
|
66
|
-
def set(key, value, expires_in =
|
65
|
+
def set(key, value, expires_in = DEFAULT_TTL)
|
67
66
|
k = build_key(key)
|
68
67
|
|
69
68
|
v = if value.nil? || (value.is_a?(String) && value.strip.empty?)
|
@@ -72,11 +71,14 @@ class RedisCacheStore
|
|
72
71
|
serialize(value)
|
73
72
|
end
|
74
73
|
|
74
|
+
expiry_int = Integer(expires_in)
|
75
|
+
expire_value = expiry_int.positive? ? expiry_int : DEFAULT_TTL
|
76
|
+
|
75
77
|
with_client do |client|
|
76
78
|
client.multi do
|
77
79
|
client.set(k, v)
|
78
80
|
|
79
|
-
client.expire(k,
|
81
|
+
client.expire(k, expire_value)
|
80
82
|
end
|
81
83
|
end
|
82
84
|
end
|
@@ -141,19 +143,11 @@ class RedisCacheStore
|
|
141
143
|
private
|
142
144
|
|
143
145
|
def serialize(object)
|
144
|
-
|
145
|
-
Marshal::dump(object)
|
146
|
-
else
|
147
|
-
Oj.dump(object)
|
148
|
-
end
|
146
|
+
Oj.dump(object)
|
149
147
|
end
|
150
148
|
|
151
149
|
def deserialize(object)
|
152
|
-
|
153
|
-
Marshal::load(object)
|
154
|
-
else
|
155
|
-
Oj.load(object)
|
156
|
-
end
|
150
|
+
Oj.load(object)
|
157
151
|
end
|
158
152
|
|
159
153
|
def build_key(key)
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_store_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,16 +42,44 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: redis
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +123,7 @@ files:
|
|
95
123
|
- lib/cache_store_redis/redis_connection.rb
|
96
124
|
- lib/cache_store_redis/redis_connection_pool.rb
|
97
125
|
- lib/cache_store_redis/version.rb
|
98
|
-
homepage: https://github.com/
|
126
|
+
homepage: https://github.com/sage/cache_store
|
99
127
|
licenses:
|
100
128
|
- MIT
|
101
129
|
metadata: {}
|
@@ -114,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
142
|
- !ruby/object:Gem::Version
|
115
143
|
version: '0'
|
116
144
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.5.1
|
145
|
+
rubygems_version: 3.1.2
|
119
146
|
signing_key:
|
120
147
|
specification_version: 4
|
121
148
|
summary: This is the redis cache_store implementation.
|