redis-activesupport 0.0.0 → 3.1.3.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +14 -1
- data/lib/active_support/cache/redis_store.rb +188 -0
- data/lib/redis/activesupport/version.rb +5 -0
- data/lib/redis-activesupport.rb +4 -7
- data/redis-activesupport.gemspec +15 -7
- data/test/active_support/cache/redis_store_test.rb +300 -0
- data/test/redis/activesupport/version_test.rb +7 -0
- data/test/test_helper.rb +8 -0
- metadata +144 -19
- data/lib/redis-activesupport/version.rb +0 -5
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 - 2011 Luca Guidi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Redis stores for ActiveSupport
|
2
|
+
|
3
|
+
__`redis-activesupport`__ provides a full set of stores (*Cache*) for __ActiveSupport__. It natively supports object marshalling, timeouts, single or multiple nodes and namespaces.
|
4
|
+
|
5
|
+
## Redis Installation
|
6
|
+
|
7
|
+
### Option 1: Homebrew
|
8
|
+
|
9
|
+
MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
|
10
|
+
|
11
|
+
brew install redis
|
12
|
+
|
13
|
+
### Option 2: From Source
|
14
|
+
|
15
|
+
Download and install Redis from [http://redis.io](http://redis.io/)
|
16
|
+
|
17
|
+
wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
|
18
|
+
tar -zxf redis-2.4.5.tar.gz
|
19
|
+
mv redis-2.4.5 redis
|
20
|
+
cd redis
|
21
|
+
make
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
# Gemfile
|
26
|
+
gem 'redis-activesupport'
|
27
|
+
|
28
|
+
### Cache Store: Ruby on Rails
|
29
|
+
|
30
|
+
# config/environments/production.rb
|
31
|
+
config.cache_store = :redis_store # { ... optional configuration ... }
|
32
|
+
|
33
|
+
### Cache Store: Standalone
|
34
|
+
|
35
|
+
ActiveSupport::Cache.lookup_store :redis_store # { ... optional configuration ... }
|
36
|
+
|
37
|
+
#### Configuration
|
38
|
+
|
39
|
+
For advanced configuration options, please check the [Redis Store Wiki](https://github.com/jodosha/redis-store/wiki).
|
40
|
+
|
41
|
+
## Running tests
|
42
|
+
|
43
|
+
git clone git://github.com/jodosha/redis-store.git
|
44
|
+
cd redis-store/redis-activesupport
|
45
|
+
gem install bundler --pre # required version: 1.1.rc
|
46
|
+
bundle exec rake
|
47
|
+
|
48
|
+
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle exec rake`
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
(c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
|
data/Rakefile
CHANGED
@@ -1 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
require 'rake'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rdoc/task'
|
8
|
+
rescue LoadError
|
9
|
+
require 'rake/rdoctask'
|
10
|
+
end
|
11
|
+
|
12
|
+
load 'tasks/redis.tasks.rb'
|
13
|
+
task :default => 'redis:test:suite'
|
14
|
+
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'redis-store'
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Cache
|
5
|
+
class RedisStore < Store
|
6
|
+
# Instantiate the store.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
# RedisStore.new
|
10
|
+
# # => host: localhost, port: 6379, db: 0
|
11
|
+
#
|
12
|
+
# RedisStore.new "example.com"
|
13
|
+
# # => host: example.com, port: 6379, db: 0
|
14
|
+
#
|
15
|
+
# RedisStore.new "example.com:23682"
|
16
|
+
# # => host: example.com, port: 23682, db: 0
|
17
|
+
#
|
18
|
+
# RedisStore.new "example.com:23682/1"
|
19
|
+
# # => host: example.com, port: 23682, db: 1
|
20
|
+
#
|
21
|
+
# RedisStore.new "example.com:23682/1/theplaylist"
|
22
|
+
# # => host: example.com, port: 23682, db: 1, namespace: theplaylist
|
23
|
+
#
|
24
|
+
# RedisStore.new "localhost:6379/0", "localhost:6380/0"
|
25
|
+
# # => instantiate a cluster
|
26
|
+
def initialize(*addresses)
|
27
|
+
@data = ::Redis::Factory.create(addresses)
|
28
|
+
super(addresses.extract_options!)
|
29
|
+
end
|
30
|
+
|
31
|
+
def write(name, value, options = nil)
|
32
|
+
options = merged_options(options)
|
33
|
+
instrument(:write, name, options) do |payload|
|
34
|
+
entry = options[:raw].present? ? value : Entry.new(value, options)
|
35
|
+
write_entry(namespaced_key(name, options), entry, options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Delete objects for matched keys.
|
40
|
+
#
|
41
|
+
# Example:
|
42
|
+
# cache.del_matched "rab*"
|
43
|
+
def delete_matched(matcher, options = nil)
|
44
|
+
options = merged_options(options)
|
45
|
+
instrument(:delete_matched, matcher.inspect) do
|
46
|
+
matcher = key_matcher(matcher, options)
|
47
|
+
begin
|
48
|
+
!(keys = @data.keys(matcher)).empty? && @data.del(*keys)
|
49
|
+
rescue Errno::ECONNREFUSED => e
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Reads multiple keys from the cache using a single call to the
|
56
|
+
# servers for all keys. Options can be passed in the last argument.
|
57
|
+
#
|
58
|
+
# Example:
|
59
|
+
# cache.read_multi "rabbit", "white-rabbit"
|
60
|
+
# cache.read_multi "rabbit", "white-rabbit", :raw => true
|
61
|
+
def read_multi(*names)
|
62
|
+
values = @data.mget(*names)
|
63
|
+
|
64
|
+
# Remove the options hash before mapping keys to values
|
65
|
+
names.extract_options!
|
66
|
+
|
67
|
+
result = Hash[names.zip(values)]
|
68
|
+
result.reject!{ |k,v| v.nil? }
|
69
|
+
result
|
70
|
+
end
|
71
|
+
|
72
|
+
# Increment a key in the store.
|
73
|
+
#
|
74
|
+
# If the key doesn't exist it will be initialized on 0.
|
75
|
+
# If the key exist but it isn't a Fixnum it will be initialized on 0.
|
76
|
+
#
|
77
|
+
# Example:
|
78
|
+
# We have two objects in cache:
|
79
|
+
# counter # => 23
|
80
|
+
# rabbit # => #<Rabbit:0x5eee6c>
|
81
|
+
#
|
82
|
+
# cache.increment "counter"
|
83
|
+
# cache.read "counter", :raw => true # => "24"
|
84
|
+
#
|
85
|
+
# cache.increment "counter", 6
|
86
|
+
# cache.read "counter", :raw => true # => "30"
|
87
|
+
#
|
88
|
+
# cache.increment "a counter"
|
89
|
+
# cache.read "a counter", :raw => true # => "1"
|
90
|
+
#
|
91
|
+
# cache.increment "rabbit"
|
92
|
+
# cache.read "rabbit", :raw => true # => "1"
|
93
|
+
def increment(key, amount = 1)
|
94
|
+
instrument(:increment, key, :amount => amount) do
|
95
|
+
@data.incrby key, amount
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Decrement a key in the store
|
100
|
+
#
|
101
|
+
# If the key doesn't exist it will be initialized on 0.
|
102
|
+
# If the key exist but it isn't a Fixnum it will be initialized on 0.
|
103
|
+
#
|
104
|
+
# Example:
|
105
|
+
# We have two objects in cache:
|
106
|
+
# counter # => 23
|
107
|
+
# rabbit # => #<Rabbit:0x5eee6c>
|
108
|
+
#
|
109
|
+
# cache.decrement "counter"
|
110
|
+
# cache.read "counter", :raw => true # => "22"
|
111
|
+
#
|
112
|
+
# cache.decrement "counter", 2
|
113
|
+
# cache.read "counter", :raw => true # => "20"
|
114
|
+
#
|
115
|
+
# cache.decrement "a counter"
|
116
|
+
# cache.read "a counter", :raw => true # => "-1"
|
117
|
+
#
|
118
|
+
# cache.decrement "rabbit"
|
119
|
+
# cache.read "rabbit", :raw => true # => "-1"
|
120
|
+
def decrement(key, amount = 1)
|
121
|
+
instrument(:decrement, key, :amount => amount) do
|
122
|
+
@data.decrby key, amount
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Clear all the data from the store.
|
127
|
+
def clear
|
128
|
+
instrument(:clear, nil, nil) do
|
129
|
+
@data.flushdb
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def stats
|
134
|
+
@data.info
|
135
|
+
end
|
136
|
+
|
137
|
+
# Force client reconnection, useful Unicorn deployed apps.
|
138
|
+
def reconnect
|
139
|
+
@data.reconnect
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
def write_entry(key, entry, options)
|
144
|
+
method = options && options[:unless_exist] ? :setnx : :set
|
145
|
+
@data.send method, key, entry, options
|
146
|
+
rescue Errno::ECONNREFUSED => e
|
147
|
+
false
|
148
|
+
end
|
149
|
+
|
150
|
+
def read_entry(key, options)
|
151
|
+
entry = @data.get key, options
|
152
|
+
if entry
|
153
|
+
entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
|
154
|
+
end
|
155
|
+
rescue Errno::ECONNREFUSED => e
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
|
159
|
+
##
|
160
|
+
# Implement the ActiveSupport::Cache#delete_entry
|
161
|
+
#
|
162
|
+
# It's really needed and use
|
163
|
+
#
|
164
|
+
def delete_entry(key, options)
|
165
|
+
@data.del key
|
166
|
+
rescue Errno::ECONNREFUSED => e
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
# Add the namespace defined in the options to a pattern designed to match keys.
|
172
|
+
#
|
173
|
+
# This implementation is __different__ than ActiveSupport:
|
174
|
+
# __it doesn't accept Regular expressions__, because the Redis matcher is designed
|
175
|
+
# only for strings with wildcards.
|
176
|
+
def key_matcher(pattern, options)
|
177
|
+
prefix = options[:namespace].is_a?(Proc) ? options[:namespace].call : options[:namespace]
|
178
|
+
if prefix
|
179
|
+
raise "Regexps aren't supported, please use string with wildcards." if pattern.is_a?(Regexp)
|
180
|
+
"#{prefix}:#{pattern}"
|
181
|
+
else
|
182
|
+
pattern
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
data/lib/redis-activesupport.rb
CHANGED
data/redis-activesupport.gemspec
CHANGED
@@ -1,22 +1,30 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "redis
|
3
|
+
require "redis/activesupport/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "redis-activesupport"
|
7
|
-
s.version = Redis::
|
7
|
+
s.version = Redis::ActiveSupport::VERSION
|
8
8
|
s.authors = ["Luca Guidi"]
|
9
9
|
s.email = ["guidi.luca@gmail.com"]
|
10
10
|
s.homepage = "http://jodosha.github.com/redis-store"
|
11
|
-
s.summary = %q{Redis for ActiveSupport}
|
12
|
-
s.description = %q{Redis for ActiveSupport}
|
11
|
+
s.summary = %q{Redis store for ActiveSupport::Cache}
|
12
|
+
s.description = %q{Redis store for ActiveSupport::Cache}
|
13
|
+
|
14
|
+
s.rubyforge_project = "redis-activesupport"
|
13
15
|
|
14
16
|
s.files = `git ls-files`.split("\n")
|
15
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
19
|
s.require_paths = ["lib"]
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
s.add_runtime_dependency 'redis-store', '1.1.0.rc'
|
22
|
+
s.add_runtime_dependency 'activesupport', '3.1.3'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rake', '~> 0.9.2.2'
|
25
|
+
s.add_development_dependency 'bundler', '~> 1.1.rc'
|
26
|
+
s.add_development_dependency 'mocha', '~> 0.10.0'
|
27
|
+
s.add_development_dependency 'minitest', '~> 2.8.0'
|
28
|
+
s.add_development_dependency 'purdytest', '~> 1.0.0'
|
22
29
|
end
|
30
|
+
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe ActiveSupport::Cache::RedisStore do
|
4
|
+
def setup
|
5
|
+
@store = ActiveSupport::Cache::RedisStore.new
|
6
|
+
@dstore = ActiveSupport::Cache::RedisStore.new "redis://127.0.0.1:6380/1", "redis://127.0.0.1:6381/1"
|
7
|
+
@rabbit = OpenStruct.new :name => "bunny"
|
8
|
+
@white_rabbit = OpenStruct.new :color => "white"
|
9
|
+
|
10
|
+
with_store_management do |store|
|
11
|
+
store.write "rabbit", @rabbit
|
12
|
+
store.delete "counter"
|
13
|
+
store.delete "rub-a-dub"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "reads the data" do
|
18
|
+
with_store_management do |store|
|
19
|
+
store.read("rabbit").must_equal(@rabbit)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "writes the data" do
|
24
|
+
with_store_management do |store|
|
25
|
+
store.write "rabbit", @white_rabbit
|
26
|
+
store.read("rabbit").must_equal(@white_rabbit)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "writes the data with expiration time" do
|
31
|
+
with_store_management do |store|
|
32
|
+
store.write "rabbit", @white_rabbit, :expires_in => 1.second
|
33
|
+
# store.read("rabbit").must_equal(@white_rabbit)
|
34
|
+
sleep 2
|
35
|
+
store.read("rabbit").must_be_nil
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does't write data if :unless_exist option is true" do
|
40
|
+
with_store_management do |store|
|
41
|
+
store.write "rabbit", @white_rabbit, :unless_exist => true
|
42
|
+
store.read("rabbit").must_equal(@rabbit)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if RUBY_VERSION.match /1\.9/
|
47
|
+
it "reads raw data" do
|
48
|
+
with_store_management do |store|
|
49
|
+
result = store.read("rabbit", :raw => true)
|
50
|
+
result.must_include("ActiveSupport::Cache::Entry")
|
51
|
+
result.must_include("\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
it "reads raw data" do
|
56
|
+
with_store_management do |store|
|
57
|
+
result = store.read("rabbit", :raw => true)
|
58
|
+
result.must_include("ActiveSupport::Cache::Entry")
|
59
|
+
result.must_include("\017OpenStruct{\006:\tname\"\nbunny")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "writes raw data" do
|
65
|
+
with_store_management do |store|
|
66
|
+
store.write "rabbit", @white_rabbit, :raw => true
|
67
|
+
store.read("rabbit", :raw => true).must_equal(%(#<OpenStruct color=\"white\">))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "deletes data" do
|
72
|
+
with_store_management do |store|
|
73
|
+
store.delete "rabbit"
|
74
|
+
store.read("rabbit").must_be_nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "deletes matched data" do
|
79
|
+
with_store_management do |store|
|
80
|
+
store.delete_matched "rabb*"
|
81
|
+
store.read("rabbit").must_be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "verifies existence of an object in the store" do
|
86
|
+
with_store_management do |store|
|
87
|
+
store.exist?("rabbit").must_equal(true)
|
88
|
+
store.exist?("rab-a-dub").must_equal(false)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "increments a key" do
|
93
|
+
with_store_management do |store|
|
94
|
+
3.times { store.increment "counter" }
|
95
|
+
store.read("counter", :raw => true).to_i.must_equal(3)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "decrements a key" do
|
100
|
+
with_store_management do |store|
|
101
|
+
3.times { store.increment "counter" }
|
102
|
+
2.times { store.decrement "counter" }
|
103
|
+
store.read("counter", :raw => true).to_i.must_equal(1)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "increments a raw key" do
|
108
|
+
with_store_management do |store|
|
109
|
+
assert store.write("raw-counter", 1, :raw => true)
|
110
|
+
store.increment("raw-counter", 2)
|
111
|
+
store.read("raw-counter", :raw => true).to_i.must_equal(3)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "decrements a raw key" do
|
116
|
+
with_store_management do |store|
|
117
|
+
assert store.write("raw-counter", 3, :raw => true)
|
118
|
+
store.decrement("raw-counter", 2)
|
119
|
+
store.read("raw-counter", :raw => true).to_i.must_equal(1)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "increments a key by given value" do
|
124
|
+
with_store_management do |store|
|
125
|
+
store.increment "counter", 3
|
126
|
+
store.read("counter", :raw => true).to_i.must_equal(3)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "decrements a key by given value" do
|
131
|
+
with_store_management do |store|
|
132
|
+
3.times { store.increment "counter" }
|
133
|
+
store.decrement "counter", 2
|
134
|
+
store.read("counter", :raw => true).to_i.must_equal(1)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "clears the store" do
|
139
|
+
with_store_management do |store|
|
140
|
+
store.clear
|
141
|
+
store.instance_variable_get(:@data).keys("*").flatten.must_be_empty
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it "provides store stats" do
|
146
|
+
with_store_management do |store|
|
147
|
+
store.stats.wont_be_empty
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "fetches data" do
|
152
|
+
with_store_management do |store|
|
153
|
+
store.fetch("rabbit").must_equal(@rabbit)
|
154
|
+
store.fetch("rub-a-dub").must_be_nil
|
155
|
+
store.fetch("rub-a-dub") { "Flora de Cana" }
|
156
|
+
store.fetch("rub-a-dub").must_equal("Flora de Cana")
|
157
|
+
store.fetch("rabbit", :force => true) # force cache miss
|
158
|
+
store.fetch("rabbit", :force => true, :expires_in => 1.second) { @white_rabbit }
|
159
|
+
# store.fetch("rabbit").must_equal(@white_rabbit)
|
160
|
+
sleep 2
|
161
|
+
store.fetch("rabbit").must_be_nil
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "reads multiple keys" do
|
166
|
+
@store.write "irish whisky", "Jameson"
|
167
|
+
result = @store.read_multi "rabbit", "irish whisky"
|
168
|
+
result['rabbit'].raw_value.must_equal(@rabbit)
|
169
|
+
result['irish whisky'].raw_value.must_equal("Jameson")
|
170
|
+
end
|
171
|
+
|
172
|
+
it "reads multiple keys and returns only the matched ones" do
|
173
|
+
@store.delete 'irish whisky'
|
174
|
+
result = @store.read_multi "rabbit", "irish whisky"
|
175
|
+
result.wont_include('irish whisky')
|
176
|
+
result.must_include('rabbit')
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "notifications" do
|
180
|
+
it "notifies on #fetch" do
|
181
|
+
with_notifications do
|
182
|
+
@store.fetch("radiohead") { "House Of Cards" }
|
183
|
+
end
|
184
|
+
|
185
|
+
read, generate, write = @events
|
186
|
+
|
187
|
+
read.name.must_equal('cache_read.active_support')
|
188
|
+
read.payload.must_equal({ :key => 'radiohead', :super_operation => :fetch })
|
189
|
+
|
190
|
+
generate.name.must_equal('cache_generate.active_support')
|
191
|
+
generate.payload.must_equal({ :key => 'radiohead' })
|
192
|
+
|
193
|
+
write.name.must_equal('cache_write.active_support')
|
194
|
+
write.payload.must_equal({ :key => 'radiohead' })
|
195
|
+
end
|
196
|
+
|
197
|
+
it "notifies on #read" do
|
198
|
+
with_notifications do
|
199
|
+
@store.read "metallica"
|
200
|
+
end
|
201
|
+
|
202
|
+
read = @events.first
|
203
|
+
read.name.must_equal('cache_read.active_support')
|
204
|
+
read.payload.must_equal({ :key => 'metallica', :hit => false })
|
205
|
+
end
|
206
|
+
|
207
|
+
it "notifies on #write" do
|
208
|
+
with_notifications do
|
209
|
+
@store.write "depeche mode", "Enjoy The Silence"
|
210
|
+
end
|
211
|
+
|
212
|
+
write = @events.first
|
213
|
+
write.name.must_equal('cache_write.active_support')
|
214
|
+
write.payload.must_equal({ :key => 'depeche mode' })
|
215
|
+
end
|
216
|
+
|
217
|
+
it "notifies on #delete" do
|
218
|
+
with_notifications do
|
219
|
+
@store.delete "the new cardigans"
|
220
|
+
end
|
221
|
+
|
222
|
+
delete = @events.first
|
223
|
+
delete.name.must_equal('cache_delete.active_support')
|
224
|
+
delete.payload.must_equal({ :key => 'the new cardigans' })
|
225
|
+
end
|
226
|
+
|
227
|
+
it "notifies on #exist?" do
|
228
|
+
with_notifications do
|
229
|
+
@store.exist? "the smiths"
|
230
|
+
end
|
231
|
+
|
232
|
+
exist = @events.first
|
233
|
+
exist.name.must_equal('cache_exist?.active_support')
|
234
|
+
exist.payload.must_equal({ :key => 'the smiths' })
|
235
|
+
end
|
236
|
+
|
237
|
+
it "notifies on #delete_matched" do
|
238
|
+
with_notifications do
|
239
|
+
@store.delete_matched "afterhours*"
|
240
|
+
end
|
241
|
+
|
242
|
+
delete_matched = @events.first
|
243
|
+
delete_matched.name.must_equal('cache_delete_matched.active_support')
|
244
|
+
delete_matched.payload.must_equal({ :key => %("afterhours*") })
|
245
|
+
end
|
246
|
+
|
247
|
+
it "notifies on #increment" do
|
248
|
+
with_notifications do
|
249
|
+
@store.increment "pearl jam"
|
250
|
+
end
|
251
|
+
|
252
|
+
increment = @events.first
|
253
|
+
increment.name.must_equal('cache_increment.active_support')
|
254
|
+
increment.payload.must_equal({ :key => 'pearl jam', :amount => 1 })
|
255
|
+
end
|
256
|
+
|
257
|
+
it "notifies on #decrement" do
|
258
|
+
with_notifications do
|
259
|
+
@store.decrement "placebo"
|
260
|
+
end
|
261
|
+
|
262
|
+
decrement = @events.first
|
263
|
+
decrement.name.must_equal('cache_decrement.active_support')
|
264
|
+
decrement.payload.must_equal({ :key => 'placebo', :amount => 1 })
|
265
|
+
end
|
266
|
+
|
267
|
+
# it "notifies on cleanup" # TODO implement in ActiveSupport::Cache::RedisStore
|
268
|
+
|
269
|
+
it "should notify on clear" do
|
270
|
+
with_notifications do
|
271
|
+
@store.clear
|
272
|
+
end
|
273
|
+
|
274
|
+
clear = @events.first
|
275
|
+
clear.name.must_equal('cache_clear.active_support')
|
276
|
+
clear.payload.must_equal({ :key => nil })
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
private
|
281
|
+
def instantiate_store(addresses = nil)
|
282
|
+
ActiveSupport::Cache::RedisStore.new(addresses).instance_variable_get(:@data)
|
283
|
+
end
|
284
|
+
|
285
|
+
def with_store_management
|
286
|
+
yield @store
|
287
|
+
yield @dstore
|
288
|
+
end
|
289
|
+
|
290
|
+
def with_notifications
|
291
|
+
@events = [ ]
|
292
|
+
ActiveSupport::Cache::RedisStore.instrument = true
|
293
|
+
ActiveSupport::Notifications.subscribe(/^cache_(.*)\.active_support$/) do |*args|
|
294
|
+
@events << ActiveSupport::Notifications::Event.new(*args)
|
295
|
+
end
|
296
|
+
yield
|
297
|
+
ActiveSupport::Cache::RedisStore.instrument = false
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 7712046
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
- rc
|
11
|
+
version: 3.1.3.rc
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Luca Guidi
|
@@ -15,10 +16,123 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-
|
19
|
-
dependencies:
|
20
|
-
|
21
|
-
|
19
|
+
date: 2011-12-30 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: redis-store
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7712002
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- rc
|
35
|
+
version: 1.1.0.rc
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: activesupport
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - "="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 5
|
47
|
+
segments:
|
48
|
+
- 3
|
49
|
+
- 1
|
50
|
+
- 3
|
51
|
+
version: 3.1.3
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rake
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 11
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 9
|
66
|
+
- 2
|
67
|
+
- 2
|
68
|
+
version: 0.9.2.2
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id003
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: bundler
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 7712070
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 1
|
83
|
+
- rc
|
84
|
+
version: 1.1.rc
|
85
|
+
type: :development
|
86
|
+
version_requirements: *id004
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: mocha
|
89
|
+
prerelease: false
|
90
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 55
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
- 10
|
99
|
+
- 0
|
100
|
+
version: 0.10.0
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id005
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: minitest
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 47
|
112
|
+
segments:
|
113
|
+
- 2
|
114
|
+
- 8
|
115
|
+
- 0
|
116
|
+
version: 2.8.0
|
117
|
+
type: :development
|
118
|
+
version_requirements: *id006
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: purdytest
|
121
|
+
prerelease: false
|
122
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ~>
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 23
|
128
|
+
segments:
|
129
|
+
- 1
|
130
|
+
- 0
|
131
|
+
- 0
|
132
|
+
version: 1.0.0
|
133
|
+
type: :development
|
134
|
+
version_requirements: *id007
|
135
|
+
description: Redis store for ActiveSupport::Cache
|
22
136
|
email:
|
23
137
|
- guidi.luca@gmail.com
|
24
138
|
executables: []
|
@@ -30,10 +144,16 @@ extra_rdoc_files: []
|
|
30
144
|
files:
|
31
145
|
- .gitignore
|
32
146
|
- Gemfile
|
147
|
+
- MIT-LICENSE
|
148
|
+
- README.md
|
33
149
|
- Rakefile
|
150
|
+
- lib/active_support/cache/redis_store.rb
|
34
151
|
- lib/redis-activesupport.rb
|
35
|
-
- lib/redis
|
152
|
+
- lib/redis/activesupport/version.rb
|
36
153
|
- redis-activesupport.gemspec
|
154
|
+
- test/active_support/cache/redis_store_test.rb
|
155
|
+
- test/redis/activesupport/version_test.rb
|
156
|
+
- test/test_helper.rb
|
37
157
|
homepage: http://jodosha.github.com/redis-store
|
38
158
|
licenses: []
|
39
159
|
|
@@ -54,18 +174,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
175
|
none: false
|
56
176
|
requirements:
|
57
|
-
- - "
|
177
|
+
- - ">"
|
58
178
|
- !ruby/object:Gem::Version
|
59
|
-
hash:
|
179
|
+
hash: 25
|
60
180
|
segments:
|
61
|
-
-
|
62
|
-
|
181
|
+
- 1
|
182
|
+
- 3
|
183
|
+
- 1
|
184
|
+
version: 1.3.1
|
63
185
|
requirements: []
|
64
186
|
|
65
|
-
rubyforge_project:
|
187
|
+
rubyforge_project: redis-activesupport
|
66
188
|
rubygems_version: 1.8.6
|
67
189
|
signing_key:
|
68
190
|
specification_version: 3
|
69
|
-
summary: Redis for ActiveSupport
|
70
|
-
test_files:
|
71
|
-
|
191
|
+
summary: Redis store for ActiveSupport::Cache
|
192
|
+
test_files:
|
193
|
+
- test/active_support/cache/redis_store_test.rb
|
194
|
+
- test/redis/activesupport/version_test.rb
|
195
|
+
- test/test_helper.rb
|
196
|
+
has_rdoc:
|