fault_tolerant_redis-activesupport 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +3 -37
- data/Rakefile +8 -0
- data/fault_tolerant_redis-activesupport.gemspec +4 -3
- data/test/active_support/cache/redis_store_test.rb +66 -130
- data/test/redis/activesupport/version_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/wercker.yml +33 -0
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4532b70a5ec5ce8ff27d08383b89731d69fa4092
|
4
|
+
data.tar.gz: b9c2c8148d91ea1e868b4c2008b72cb5916a8884
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28da90884df96978e424977916a33ba319665259510308cb0a7097e86b82e0949d9e42b69524a103dc19fe4bf3095e4ab4eccf7a46a486069b3e1847feebbd0d
|
7
|
+
data.tar.gz: d90d98bcf89b1eb37af91f3b1b5685d1f4bbafefc98a00e986b8891d08509679bb8e6a483ef3ebf2b5d5103e27241463a42a6d2758ccf745df047c45ee7af522
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails-redis_tolerant_cache_store
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/README.md
CHANGED
@@ -1,38 +1,4 @@
|
|
1
|
-
|
1
|
+
[![wercker status](https://app.wercker.com/status/21cb26b06b1e5565aa6b26007a0bdd1c/m "wercker status")](https://app.wercker.com/project/bykey/21cb26b06b1e5565aa6b26007a0bdd1c)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
# Gemfile
|
9
|
-
gem 'redis-activesupport'
|
10
|
-
```
|
11
|
-
|
12
|
-
## Usage
|
13
|
-
|
14
|
-
If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/redis-store/redis-rails) instead. For standalone usage:
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
ActiveSupport::Cache.lookup_store :redis_store # { ... optional configuration ... }
|
18
|
-
```
|
19
|
-
|
20
|
-
## Running tests
|
21
|
-
|
22
|
-
```shell
|
23
|
-
gem install bundler
|
24
|
-
git clone git://github.com/redis-store/redis-activesupport.git
|
25
|
-
cd redis-activesupport
|
26
|
-
bundle install
|
27
|
-
bundle exec rake
|
28
|
-
```
|
29
|
-
|
30
|
-
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
|
31
|
-
|
32
|
-
## Status
|
33
|
-
|
34
|
-
[![Gem Version](https://badge.fury.io/rb/redis-activesupport.png)](http://badge.fury.io/rb/redis-activesupport) [![Build Status](https://secure.travis-ci.org/redis-store/redis-activesupport.png?branch=master)](http://travis-ci.org/jodosha/redis-activesupport?branch=master) [![Code Climate](https://codeclimate.com/github/jodosha/redis-store.png)](https://codeclimate.com/github/redis-store/redis-activesupport)
|
35
|
-
|
36
|
-
## Copyright
|
37
|
-
|
38
|
-
2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
|
3
|
+
# Fault tolerant Redis store for ActiveSupport
|
4
|
+
A combination of https://github.com/redis-store/redis-activesupport and https://github.com/renra/ruby-maybe_client
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'redis/activesupport/version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'fault_tolerant_redis-activesupport'
|
7
|
-
s.version =
|
7
|
+
s.version = '4.0.1'
|
8
8
|
s.authors = ['Luca Guidi', 'Jan Renra Gloser']
|
9
9
|
s.email = ['me@lucaguidi.com', 'jan.renra.gloser@gmail.com']
|
10
10
|
s.homepage = 'https://github.com/renra/redis-activesupport'
|
@@ -20,13 +20,14 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
|
22
22
|
s.add_runtime_dependency 'redis-store', '~> 1.1.0'
|
23
|
-
s.add_runtime_dependency 'activesupport', '~> 4'
|
24
|
-
s.add_runtime_dependency 'maybe_client', '1.
|
23
|
+
s.add_runtime_dependency 'activesupport', '~> 4.0.0'
|
24
|
+
s.add_runtime_dependency 'maybe_client', '1.2'
|
25
25
|
|
26
26
|
s.add_development_dependency 'rake', '~> 10'
|
27
27
|
s.add_development_dependency 'bundler', '~> 1.3'
|
28
28
|
s.add_development_dependency 'mocha', '~> 0.14.0'
|
29
29
|
s.add_development_dependency 'minitest', '~> 4.2'
|
30
|
+
s.add_development_dependency 'pry'
|
30
31
|
s.add_development_dependency 'redis-store-testing'
|
31
32
|
end
|
32
33
|
|
@@ -1,185 +1,126 @@
|
|
1
|
-
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'pry'
|
2
4
|
|
3
|
-
describe ActiveSupport::Cache::
|
5
|
+
describe ActiveSupport::Cache::FaultTolerantRedisStore do
|
4
6
|
def setup
|
5
|
-
@store = ActiveSupport::Cache::
|
6
|
-
@dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"
|
7
|
+
@store = ActiveSupport::Cache::FaultTolerantRedisStore.new
|
7
8
|
@rabbit = OpenStruct.new :name => "bunny"
|
8
9
|
@white_rabbit = OpenStruct.new :color => "white"
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
store.delete "rub-a-dub"
|
14
|
-
end
|
11
|
+
@store.write "rabbit", @rabbit
|
12
|
+
@store.delete "counter"
|
13
|
+
@store.delete "rub-a-dub"
|
15
14
|
end
|
16
15
|
|
17
16
|
it "reads the data" do
|
18
|
-
|
19
|
-
store.read("rabbit").must_equal(@rabbit)
|
20
|
-
end
|
17
|
+
@store.read('rabbit').must_equal(@rabbit)
|
21
18
|
end
|
22
19
|
|
23
20
|
it "writes the data" do
|
24
|
-
|
25
|
-
|
26
|
-
store.read("rabbit").must_equal(@white_rabbit)
|
27
|
-
end
|
21
|
+
@store.write "rabbit", @white_rabbit
|
22
|
+
@store.read("rabbit").must_equal(@white_rabbit)
|
28
23
|
end
|
29
24
|
|
30
25
|
it "writes the data with expiration time" do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
store.read("rabbit").must_be_nil
|
36
|
-
end
|
26
|
+
@store.write "rabbit", @white_rabbit, :expires_in => 1.second
|
27
|
+
@store.read("rabbit").must_equal(@white_rabbit)
|
28
|
+
sleep 1
|
29
|
+
@store.read("rabbit").must_be_nil
|
37
30
|
end
|
38
31
|
|
39
32
|
it "respects expiration time in seconds" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
store.read("rabbit").must_be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "respects expiration time in minutes" do
|
50
|
-
with_store_management do |store|
|
51
|
-
store.write "rabbit", @white_rabbit
|
52
|
-
store.read("rabbit").must_equal(@white_rabbit)
|
53
|
-
store.expire "rabbit", 1.minutes
|
54
|
-
sleep 61
|
55
|
-
store.read("rabbit").must_be_nil
|
56
|
-
end
|
33
|
+
@store.write "rabbit", @white_rabbit
|
34
|
+
@store.read("rabbit").must_equal(@white_rabbit)
|
35
|
+
@store.expire "rabbit", 1.second
|
36
|
+
sleep 1.2 # Wercker needs more than 1 second for some reason
|
37
|
+
@store.read("rabbit").must_be_nil
|
57
38
|
end
|
58
39
|
|
59
40
|
it "does't write data if :unless_exist option is true" do
|
60
|
-
|
61
|
-
|
62
|
-
store.read("rabbit").must_equal(@rabbit)
|
63
|
-
end
|
41
|
+
@store.write "rabbit", @white_rabbit, :unless_exist => true
|
42
|
+
@store.read("rabbit").must_equal(@rabbit)
|
64
43
|
end
|
65
44
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
result.must_include("ActiveSupport::Cache::Entry")
|
71
|
-
result.must_include("\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
else
|
75
|
-
it "reads raw data" do
|
76
|
-
with_store_management do |store|
|
77
|
-
result = store.read("rabbit", :raw => true)
|
78
|
-
result.must_include("ActiveSupport::Cache::Entry")
|
79
|
-
result.must_include("\017OpenStruct{\006:\tname")
|
80
|
-
end
|
81
|
-
end
|
45
|
+
it "reads raw data" do
|
46
|
+
result = @store.read("rabbit", :raw => true)
|
47
|
+
result.must_include("ActiveSupport::Cache::Entry")
|
48
|
+
result.must_include("\017OpenStruct{\006:\tname")
|
82
49
|
end
|
83
50
|
|
84
51
|
it "writes raw data" do
|
85
|
-
|
86
|
-
|
87
|
-
store.read("rabbit", :raw => true).must_equal(%(#<OpenStruct color=\"white\">))
|
88
|
-
end
|
52
|
+
@store.write "rabbit", @white_rabbit, :raw => true
|
53
|
+
@store.read("rabbit", :raw => true).must_equal(%(#<OpenStruct color=\"white\">))
|
89
54
|
end
|
90
55
|
|
91
56
|
it "deletes data" do
|
92
|
-
|
93
|
-
|
94
|
-
store.read("rabbit").must_be_nil
|
95
|
-
end
|
57
|
+
@store.delete "rabbit"
|
58
|
+
@store.read("rabbit").must_be_nil
|
96
59
|
end
|
97
60
|
|
98
61
|
it "deletes matched data" do
|
99
|
-
|
100
|
-
|
101
|
-
store.read("rabbit").must_be_nil
|
102
|
-
end
|
62
|
+
@store.delete_matched "rabb*"
|
63
|
+
@store.read("rabbit").must_be_nil
|
103
64
|
end
|
104
65
|
|
105
66
|
it "verifies existence of an object in the store" do
|
106
|
-
|
107
|
-
|
108
|
-
store.exist?("rab-a-dub").must_equal(false)
|
109
|
-
end
|
67
|
+
@store.exist?("rabbit").must_equal(true)
|
68
|
+
@store.exist?("rab-a-dub").must_equal(false)
|
110
69
|
end
|
111
70
|
|
112
71
|
it "increments a key" do
|
113
|
-
|
114
|
-
|
115
|
-
store.read("counter", :raw => true).to_i.must_equal(3)
|
116
|
-
end
|
72
|
+
3.times { @store.increment "counter" }
|
73
|
+
@store.read("counter", :raw => true).to_i.must_equal(3)
|
117
74
|
end
|
118
75
|
|
119
76
|
it "decrements a key" do
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
store.read("counter", :raw => true).to_i.must_equal(1)
|
124
|
-
end
|
77
|
+
3.times { @store.increment "counter" }
|
78
|
+
2.times { @store.decrement "counter" }
|
79
|
+
@store.read("counter", :raw => true).to_i.must_equal(1)
|
125
80
|
end
|
126
81
|
|
127
82
|
it "increments a raw key" do
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
store.read("raw-counter", :raw => true).to_i.must_equal(3)
|
132
|
-
end
|
83
|
+
assert @store.write("raw-counter", 1, :raw => true)
|
84
|
+
@store.increment("raw-counter", 2)
|
85
|
+
@store.read("raw-counter", :raw => true).to_i.must_equal(3)
|
133
86
|
end
|
134
87
|
|
135
88
|
it "decrements a raw key" do
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
store.read("raw-counter", :raw => true).to_i.must_equal(1)
|
140
|
-
end
|
89
|
+
assert @store.write("raw-counter", 3, :raw => true)
|
90
|
+
@store.decrement("raw-counter", 2)
|
91
|
+
@store.read("raw-counter", :raw => true).to_i.must_equal(1)
|
141
92
|
end
|
142
93
|
|
143
94
|
it "increments a key by given value" do
|
144
|
-
|
145
|
-
|
146
|
-
store.read("counter", :raw => true).to_i.must_equal(3)
|
147
|
-
end
|
95
|
+
@store.increment "counter", 3
|
96
|
+
@store.read("counter", :raw => true).to_i.must_equal(3)
|
148
97
|
end
|
149
98
|
|
150
99
|
it "decrements a key by given value" do
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
store.read("counter", :raw => true).to_i.must_equal(1)
|
155
|
-
end
|
100
|
+
3.times { @store.increment "counter" }
|
101
|
+
@store.decrement "counter", 2
|
102
|
+
@store.read("counter", :raw => true).to_i.must_equal(1)
|
156
103
|
end
|
157
104
|
|
158
105
|
it "clears the store" do
|
159
|
-
|
160
|
-
|
161
|
-
store.instance_variable_get(:@data).keys("*").flatten.must_be_empty
|
162
|
-
end
|
106
|
+
@store.clear
|
107
|
+
@store.instance_variable_get(:@data).keys("*").flatten.must_be_empty
|
163
108
|
end
|
164
109
|
|
165
110
|
it "provides store stats" do
|
166
|
-
|
167
|
-
store.stats.wont_be_empty
|
168
|
-
end
|
111
|
+
@store.stats.wont_be_empty
|
169
112
|
end
|
170
113
|
|
171
114
|
it "fetches data" do
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
store.fetch("rabbit").must_be_nil
|
182
|
-
end
|
115
|
+
@store.fetch("rabbit").must_equal(@rabbit)
|
116
|
+
@store.fetch("rub-a-dub").must_be_nil
|
117
|
+
@store.fetch("rub-a-dub") { "Flora de Cana" }
|
118
|
+
@store.fetch("rub-a-dub").must_equal("Flora de Cana")
|
119
|
+
@store.fetch("rabbit", :force => true) # force cache miss
|
120
|
+
@store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
|
121
|
+
# store.fetch("rabbit").must_equal(@white_rabbit)
|
122
|
+
sleep 2
|
123
|
+
@store.fetch("rabbit").must_be_nil
|
183
124
|
end
|
184
125
|
|
185
126
|
it "reads multiple keys" do
|
@@ -284,7 +225,7 @@ describe ActiveSupport::Cache::RedisStore do
|
|
284
225
|
decrement.payload.must_equal({ :key => 'placebo', :amount => 1 })
|
285
226
|
end
|
286
227
|
|
287
|
-
# it "notifies on cleanup" # TODO implement in ActiveSupport::Cache::
|
228
|
+
# it "notifies on cleanup" # TODO implement in ActiveSupport::Cache::FaultTolerantRedisStore
|
288
229
|
|
289
230
|
it "should notify on clear" do
|
290
231
|
with_notifications do
|
@@ -299,22 +240,17 @@ describe ActiveSupport::Cache::RedisStore do
|
|
299
240
|
|
300
241
|
private
|
301
242
|
def instantiate_store(addresses = nil)
|
302
|
-
ActiveSupport::Cache::
|
303
|
-
end
|
304
|
-
|
305
|
-
def with_store_management
|
306
|
-
yield @store
|
307
|
-
yield @dstore
|
243
|
+
ActiveSupport::Cache::FaultTolerantRedisStore.new(addresses).instance_variable_get(:@data)
|
308
244
|
end
|
309
245
|
|
310
246
|
def with_notifications
|
311
247
|
@events = [ ]
|
312
|
-
ActiveSupport::Cache::
|
248
|
+
ActiveSupport::Cache::FaultTolerantRedisStore.instrument = true
|
313
249
|
ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
|
314
250
|
@events << ActiveSupport::Notifications::Event.new(*args)
|
315
251
|
end
|
316
252
|
yield
|
317
|
-
ActiveSupport::Cache::
|
253
|
+
ActiveSupport::Cache::FaultTolerantRedisStore.instrument = false
|
318
254
|
end
|
319
255
|
end
|
320
256
|
|
data/test/test_helper.rb
CHANGED
data/wercker.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# This references the default Ruby container from
|
2
|
+
# the Docker Hub.
|
3
|
+
# https://registry.hub.docker.com/_/ruby/
|
4
|
+
# If you want to use a specific version you would use a tag:
|
5
|
+
# ruby:2.2.2
|
6
|
+
box: ruby:2.2.3
|
7
|
+
# You can also use services such as databases. Read more on our dev center:
|
8
|
+
# http://devcenter.wercker.com/docs/services/index.html
|
9
|
+
services:
|
10
|
+
- id: redis
|
11
|
+
# - postgres
|
12
|
+
# http://devcenter.wercker.com/docs/services/postgresql.html
|
13
|
+
|
14
|
+
# - mongodb
|
15
|
+
# http://devcenter.wercker.com/docs/services/mongodb.html
|
16
|
+
|
17
|
+
# This is the build pipeline. Pipelines are the core of wercker
|
18
|
+
# Read more about pipelines on our dev center
|
19
|
+
# http://devcenter.wercker.com/docs/pipelines/index.html
|
20
|
+
build:
|
21
|
+
# Steps make up the actions in your pipeline
|
22
|
+
# Read more about steps on our dev center:
|
23
|
+
# http://devcenter.wercker.com/docs/steps/index.html
|
24
|
+
steps:
|
25
|
+
- bundle-install
|
26
|
+
|
27
|
+
- script:
|
28
|
+
name: Export Redis url
|
29
|
+
code: export REDIS_URL="redis://$REDIS_PORT_6379_TCP_ADDR:6379"
|
30
|
+
|
31
|
+
- script:
|
32
|
+
name: Run tests
|
33
|
+
code: bundle exec rake test
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fault_tolerant_redis-activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-11-
|
12
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis-store
|
@@ -31,28 +31,28 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 4.0.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 4.0.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: maybe_client
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - '='
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.
|
48
|
+
version: '1.2'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - '='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: '1.2'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +109,20 @@ dependencies:
|
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '4.2'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: pry
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: redis-store-testing
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +147,8 @@ extra_rdoc_files: []
|
|
133
147
|
files:
|
134
148
|
- ".env"
|
135
149
|
- ".gitignore"
|
150
|
+
- ".ruby-gemset"
|
151
|
+
- ".ruby-version"
|
136
152
|
- ".travis.yml"
|
137
153
|
- Gemfile
|
138
154
|
- MIT-LICENSE
|
@@ -145,6 +161,7 @@ files:
|
|
145
161
|
- test/active_support/cache/redis_store_test.rb
|
146
162
|
- test/redis/activesupport/version_test.rb
|
147
163
|
- test/test_helper.rb
|
164
|
+
- wercker.yml
|
148
165
|
homepage: https://github.com/renra/redis-activesupport
|
149
166
|
licenses:
|
150
167
|
- MIT
|