cache_store_redis 0.3.2-java → 0.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cache_store_redis/version.rb +1 -1
- data/lib/cache_store_redis.rb +45 -17
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945597672738a705803080b32c7b903c69f59210561b17c46fc48c83bcb3c5d8
|
4
|
+
data.tar.gz: 3a0106ddaab3002adf3776f2892dc2b9bb3e5f6fe8a6252fd1c372d3c623f660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3897ae95d23e4311c30a81846c2bdf4bfb0d0c9ff92ccdf8592dd6e21ffb839d7d017c6d9df2b83a42335435300c65cde8e7f0c45bc70eb1200d8903e5fd2cd6
|
7
|
+
data.tar.gz: 9efeceb991fa83b8bb3c735838a14bc3ba913e4bb66bd5faf8b0c4d77b543d5177db68cae1d8bf9732ec0e8ee6ebcb98f46fa7a395f1e9181c525be31b0f4584
|
data/lib/cache_store_redis.rb
CHANGED
@@ -1,11 +1,30 @@
|
|
1
1
|
require 'cache_store_redis/version'
|
2
2
|
require 'redis'
|
3
3
|
require 'securerandom'
|
4
|
+
require 'connection_pool'
|
4
5
|
|
5
6
|
#This class is used to implement a redis cache store.
|
6
7
|
#This class is used for interacting with a redis based cache store.
|
7
8
|
class RedisCacheStore
|
8
9
|
|
10
|
+
def self.pool(config)
|
11
|
+
@pool ||= ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
|
12
|
+
if config == nil
|
13
|
+
Redis.new
|
14
|
+
else
|
15
|
+
Redis.new(config)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.pool_size
|
21
|
+
@pool_size ||= ENV['CACHE_STORE_POOL_SIZE'] || 10
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.pool_timeout
|
25
|
+
@pool_size ||= ENV['CACHE_STORE_POOL_TIMEOUT'] || 1
|
26
|
+
end
|
27
|
+
|
9
28
|
def initialize(namespace = nil, config = nil)
|
10
29
|
|
11
30
|
if RUBY_PLATFORM != 'java'
|
@@ -13,10 +32,12 @@ class RedisCacheStore
|
|
13
32
|
end
|
14
33
|
|
15
34
|
@namespace = namespace
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
35
|
+
@config = config
|
36
|
+
end
|
37
|
+
|
38
|
+
def with_client
|
39
|
+
self.class.pool(@config).with do |client|
|
40
|
+
yield client
|
20
41
|
end
|
21
42
|
end
|
22
43
|
|
@@ -34,8 +55,6 @@ class RedisCacheStore
|
|
34
55
|
if driver != nil
|
35
56
|
config[:driver] = driver
|
36
57
|
end
|
37
|
-
|
38
|
-
@client = Redis.new(config)
|
39
58
|
end
|
40
59
|
|
41
60
|
#This method is called to set a value within this cache store by it's key.
|
@@ -51,10 +70,14 @@ class RedisCacheStore
|
|
51
70
|
v = serialize(value)
|
52
71
|
end
|
53
72
|
|
54
|
-
|
73
|
+
with_client do |client|
|
74
|
+
client.multi do
|
75
|
+
client.set(k, v)
|
55
76
|
|
56
|
-
|
57
|
-
|
77
|
+
if expires_in > 0
|
78
|
+
client.expire(k, expires_in)
|
79
|
+
end
|
80
|
+
end
|
58
81
|
end
|
59
82
|
|
60
83
|
end
|
@@ -69,7 +92,10 @@ class RedisCacheStore
|
|
69
92
|
|
70
93
|
k = build_key(key)
|
71
94
|
|
72
|
-
value =
|
95
|
+
value = with_client do |client|
|
96
|
+
client.get(k)
|
97
|
+
end
|
98
|
+
|
73
99
|
value = deserialize(value) unless value == nil
|
74
100
|
|
75
101
|
if value.nil? && block_given?
|
@@ -84,9 +110,9 @@ class RedisCacheStore
|
|
84
110
|
#
|
85
111
|
# @param key [String] This is the unique key to reference the value to remove from this cache store.
|
86
112
|
def remove(key)
|
87
|
-
|
88
|
-
|
89
|
-
|
113
|
+
with_client do |client|
|
114
|
+
client.del(build_key(key))
|
115
|
+
end
|
90
116
|
end
|
91
117
|
|
92
118
|
# This method is called to check if a value exists within this cache store for a specific key.
|
@@ -94,16 +120,18 @@ class RedisCacheStore
|
|
94
120
|
# @param key [String] This is the unique key to reference the value to check for within this cache store.
|
95
121
|
# @return [Boolean] True or False to specify if the key exists in the cache store.
|
96
122
|
def exist?(key)
|
97
|
-
|
98
|
-
|
99
|
-
|
123
|
+
with_client do |client|
|
124
|
+
client.exists(build_key(key))
|
125
|
+
end
|
100
126
|
end
|
101
127
|
|
102
128
|
# Ping the cache store.
|
103
129
|
#
|
104
130
|
# @return [String] `PONG`
|
105
131
|
def ping
|
106
|
-
|
132
|
+
with_client do |client|
|
133
|
+
client.ping
|
134
|
+
end
|
107
135
|
end
|
108
136
|
|
109
137
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_store_redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
name: connection_pool
|
76
|
+
prerelease: false
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: This is the redis cache_store implementation.
|
70
84
|
email:
|
71
85
|
- vaughan.britton@sage.com
|