cache_store_redis 0.3.2 → 0.4.0

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
2
  SHA1:
3
- metadata.gz: f084e13e3602325ec84cb76fe89d5598813e0a53
4
- data.tar.gz: e70ac165ec4185dcbdbe197ac6bd891dd1d0de4c
3
+ metadata.gz: 7965c5c2861b9dc065be5f4d9304b852e345d893
4
+ data.tar.gz: 4fd515029df97e7e85a3374d59643e8c3148ee34
5
5
  SHA512:
6
- metadata.gz: eda1b6abe1ca2bd749b2a20706107b69fba9b0e74d31269bb80ac07e5af129599fa9cb6d925a514ef90147856026a6a83435a94ee200eff3786b280856ada891
7
- data.tar.gz: ffb71b410f449b18af67372f203fe02c55e1b8b5cab2e53fbab1f2174c10c2d29505cee9f34bdfdb22041199c5bcb9fcffd6d237172ecfc86169267d31d90af1
6
+ metadata.gz: 124fcec87b5b222fe16ec7d54aac4ed66c68ea294a9a52ac7f7c9eb2e1cdcee25c5d77378545defad05e7ffe6b273883829e16589d771a32215c18db4246c4c3
7
+ data.tar.gz: bc545692d24f122c4ca8726a8ece41ac767bd2df2c82d39cc7f6319a4e56e46153b0644270c3b27e703567a7d8c64a5c915027ef5c52aa10450cabf54a837512
@@ -1,3 +1,3 @@
1
1
  module CacheStoreRedis
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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
- if config == nil
17
- @client = Redis.new
18
- else
19
- @client = Redis.new(config)
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
- @client.set(k, v)
73
+ with_client do |client|
74
+ client.multi do
75
+ client.set(k, v)
55
76
 
56
- if expires_in > 0
57
- @client.expire(k, expires_in)
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 = @client.get(k)
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
- @client.del(build_key(key))
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
- @client.exists(build_key(key))
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
- @client.ping
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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaughanbrittonsage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -53,13 +53,13 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: redis
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: redis
70
+ name: connection_pool
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="