redis_set_store 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/.rspec +2 -0
- data/.rubocop.yml +25 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Appraisals +13 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.md +157 -0
- data/Rakefile +17 -0
- data/bin/console +8 -0
- data/bin/setup +6 -0
- data/gemfiles/rails_4_2.gemfile +7 -0
- data/gemfiles/rails_4_2.gemfile.lock +178 -0
- data/gemfiles/rails_5_0.gemfile +7 -0
- data/gemfiles/rails_5_0.gemfile.lock +185 -0
- data/gemfiles/rails_5_1.gemfile +7 -0
- data/gemfiles/rails_5_1.gemfile.lock +185 -0
- data/lib/active_support/cache/redis_set_store.rb +169 -0
- data/lib/redis_set_store.rb +20 -0
- data/lib/redis_set_store/bootstrap.rb +76 -0
- data/lib/redis_set_store/railtie.rb +13 -0
- data/lib/redis_set_store/version.rb +5 -0
- data/redis_set_store.gemspec +39 -0
- metadata +240 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6ac6e8cf904c707147866668a3a1d37d972e626e
|
4
|
+
data.tar.gz: 5e1d14b39c935d4dabc255fe3529f29b6bae2428
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79db8b27bc1d7cc47275b411a9e4f5c73e93f5954d53bf6e2bf059ae1109aac0710d7e448f573a7320d9e5468bd9848589c95ebc24ad09a1ff4430b72d08cc80
|
7
|
+
data.tar.gz: 54d6ee3eb1528c1e50c300224e54f5cf13c4e359083c889cde83100b747bfa742e6fae273c57e8778e5bd8c723da4bbcf2eb29a4337ed80489fbfd76e3b5a9ce
|
data/.gitignore
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
.rspec_status
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
# Bundler artifacts
|
22
|
+
/Gemfile.lock
|
23
|
+
/coverage/
|
24
|
+
/doc/
|
25
|
+
*.bundle
|
26
|
+
*.so
|
27
|
+
*.o
|
28
|
+
*.a
|
29
|
+
mkmf.log
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Documentation:
|
2
|
+
Exclude:
|
3
|
+
- "**/railtie.rb"
|
4
|
+
- "spec/**/*"
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 120
|
10
|
+
Layout/AlignHash:
|
11
|
+
EnforcedHashRocketStyle: table
|
12
|
+
EnforcedColonStyle: table
|
13
|
+
Layout/SpaceInsideHashLiteralBraces:
|
14
|
+
EnforcedStyle: no_space
|
15
|
+
Style/RaiseArgs:
|
16
|
+
EnforcedStyle: compact
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Exclude:
|
20
|
+
- "redis_set_store.gemspec"
|
21
|
+
- "spec/**/*"
|
22
|
+
|
23
|
+
Layout/EmptyLinesAroundBlockBody:
|
24
|
+
Exclude:
|
25
|
+
- "spec/**/*"
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
redis_set_store
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Nine By Blue
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# RedisSetStore
|
2
|
+
|
3
|
+
A Rails cache implementation that is backed by redis and uses sets to track
|
4
|
+
keys for rapid expiration of large numbers of keys.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'redis_set_store'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install redis_set_store
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You can use the `RedisSetStore` as you would any other Rails cache store by
|
25
|
+
configuring it in your environment files:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# config/application.rb
|
29
|
+
config.cache_store = :redis_set_store
|
30
|
+
```
|
31
|
+
|
32
|
+
`RedisSetStore` allows you to regularly remove large numbers of keys with
|
33
|
+
wildcard patterns, using `#delete_matched`.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
def cache_key_prefix
|
37
|
+
"#{self.class.to_s.tableize.singularize}:#{id}:"
|
38
|
+
end
|
39
|
+
|
40
|
+
def expire_cache
|
41
|
+
Rails.cache.delete_matched("#{cache_key_prefix}*")
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
### How it works
|
46
|
+
|
47
|
+
Under the original [`RedisStore`](https://github.com/redis-store/redis-store)
|
48
|
+
`#delete_matched` calls the Redis `KEYS` method which scans _every_ key in your
|
49
|
+
database. If you have millions of cache keys this can take a long time and make
|
50
|
+
your server unresponsive.
|
51
|
+
|
52
|
+
`RedisSetStore` resolves this by maintaining a `set` of keys and checking the
|
53
|
+
members of that set when matching. Additionally, it partitions sets based on
|
54
|
+
a pattern. The default pattern is `\A[^:]\d+`, so if you have keys named as
|
55
|
+
follows, there would be a set for each object (e.g. `user:1`, `user:2`,
|
56
|
+
`report:1`, etc.):
|
57
|
+
|
58
|
+
```
|
59
|
+
user:1:profile
|
60
|
+
user:1:reports
|
61
|
+
user:2:profile
|
62
|
+
user:2:reports
|
63
|
+
report:1:metadata
|
64
|
+
report:2:metadata
|
65
|
+
```
|
66
|
+
|
67
|
+
Partitioning the sets allows for much faster look up of matched keys because
|
68
|
+
the cache doesn't have to retrieve all the keys in your database and try to
|
69
|
+
match every one.
|
70
|
+
|
71
|
+
Depending on your cache names, you may want to use a different pattern. You
|
72
|
+
can configure this with the first parameter to the `cache_store` configuration
|
73
|
+
value as shown above (e.g. `/\Auser:\d+/`). Note that the pattern does not have
|
74
|
+
to be a prefix. It could match any part of the key.
|
75
|
+
|
76
|
+
### Configuration
|
77
|
+
|
78
|
+
In your `config/application.rb`, (or files in `config/environments`), you can
|
79
|
+
pass a regular expression to partition your keys for sets and parameters for
|
80
|
+
the redis instance to connect to. If you don't want to change the default
|
81
|
+
partitioning pattern, the redis options can be the first parameter:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
config.cache_store = :redis_set_store
|
85
|
+
# or
|
86
|
+
config.cache_store = :redis_set_store, "redis://localhost:6379/0"
|
87
|
+
# or
|
88
|
+
config.cache_store = :redis_set_store, {
|
89
|
+
host: "localhost",
|
90
|
+
port: 6379,
|
91
|
+
db: 0,
|
92
|
+
password: "mysecret",
|
93
|
+
namespace: "cache"
|
94
|
+
}
|
95
|
+
```
|
96
|
+
|
97
|
+
If you are setting the regular expression for partitioning, then you must pass
|
98
|
+
that as the first parameter, and redis configuration follows.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
config.cache_store = :redis_set_store, /\Auser:\d+/
|
102
|
+
# or
|
103
|
+
config.cache_store = :redis_set_store, /\Auser:\d+/, "redis://localhost:6379/0"
|
104
|
+
# or
|
105
|
+
config.cache_store = :redis_set_store, /\Auser:\d+/, {
|
106
|
+
host: "localhost",
|
107
|
+
port: 6379,
|
108
|
+
db: 0,
|
109
|
+
password: "mysecret",
|
110
|
+
namespace: "cache"
|
111
|
+
}
|
112
|
+
```
|
113
|
+
|
114
|
+
See the [`redis-rails`](https://github.com/redis-store/redis-rails) gem for
|
115
|
+
more details on how to configure the redis connection.
|
116
|
+
|
117
|
+
### Migrating an Existing Cache
|
118
|
+
|
119
|
+
As `RedisSetStore` looks up cache keys in redis sets, if you have an existing
|
120
|
+
cache, then those set entries won't exist for the existing cache entries and
|
121
|
+
the `RedisSetStore#matched` and `RedisSetStore#delete_matched` methods won't
|
122
|
+
find any keys.
|
123
|
+
|
124
|
+
To address this we provide the `RedisSetStore::Bootstrap` utility. See the
|
125
|
+
documentation for that class for details.
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
1. Fork it ( https://github.com/keylimetoolbox/redis_set_store/fork )
|
130
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
131
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
132
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
133
|
+
5. Create a new Pull Request
|
134
|
+
|
135
|
+
|
136
|
+
### Redis Installation
|
137
|
+
|
138
|
+
#### Option 1: Homebrew
|
139
|
+
|
140
|
+
MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to
|
141
|
+
install Redis:
|
142
|
+
|
143
|
+
```shell
|
144
|
+
brew install redis
|
145
|
+
```
|
146
|
+
|
147
|
+
#### Option 2: From Source
|
148
|
+
|
149
|
+
Download and install Redis from [the download page](http://redis.io//download)
|
150
|
+
and follow the instructions.
|
151
|
+
|
152
|
+
### Running tests
|
153
|
+
|
154
|
+
```shell
|
155
|
+
bin/setup
|
156
|
+
bundle exec rake
|
157
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "redis_set_store"
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "rubocop/rake_task"
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
require "bundler/audit/task"
|
11
|
+
Bundler::Audit::Task.new
|
12
|
+
|
13
|
+
# Remove default and replace with a series of test tasks
|
14
|
+
task default: []
|
15
|
+
Rake::Task[:default].clear
|
16
|
+
|
17
|
+
task default: %w[spec rubocop bundle:audit]
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
redis_set_store (0.1.0)
|
5
|
+
activesupport (>= 4.2)
|
6
|
+
railties (>= 4.2)
|
7
|
+
redis (~> 3.0)
|
8
|
+
redis-rails (~> 5.0)
|
9
|
+
redis-store (~> 1.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actionmailer (4.2.9)
|
15
|
+
actionpack (= 4.2.9)
|
16
|
+
actionview (= 4.2.9)
|
17
|
+
activejob (= 4.2.9)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
20
|
+
actionpack (4.2.9)
|
21
|
+
actionview (= 4.2.9)
|
22
|
+
activesupport (= 4.2.9)
|
23
|
+
rack (~> 1.6)
|
24
|
+
rack-test (~> 0.6.2)
|
25
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (4.2.9)
|
28
|
+
activesupport (= 4.2.9)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (4.2.9)
|
34
|
+
activesupport (= 4.2.9)
|
35
|
+
globalid (>= 0.3.0)
|
36
|
+
activemodel (4.2.9)
|
37
|
+
activesupport (= 4.2.9)
|
38
|
+
builder (~> 3.1)
|
39
|
+
activerecord (4.2.9)
|
40
|
+
activemodel (= 4.2.9)
|
41
|
+
activesupport (= 4.2.9)
|
42
|
+
arel (~> 6.0)
|
43
|
+
activesupport (4.2.9)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
47
|
+
tzinfo (~> 1.1)
|
48
|
+
appraisal (2.2.0)
|
49
|
+
bundler
|
50
|
+
rake
|
51
|
+
thor (>= 0.14.0)
|
52
|
+
arel (6.0.4)
|
53
|
+
ast (2.3.0)
|
54
|
+
builder (3.2.3)
|
55
|
+
bundler-audit (0.6.0)
|
56
|
+
bundler (~> 1.2)
|
57
|
+
thor (~> 0.18)
|
58
|
+
concurrent-ruby (1.0.5)
|
59
|
+
diff-lcs (1.3)
|
60
|
+
erubis (2.7.0)
|
61
|
+
globalid (0.4.0)
|
62
|
+
activesupport (>= 4.2.0)
|
63
|
+
i18n (0.8.6)
|
64
|
+
loofah (2.0.3)
|
65
|
+
nokogiri (>= 1.5.9)
|
66
|
+
mail (2.6.6)
|
67
|
+
mime-types (>= 1.16, < 4)
|
68
|
+
metaclass (0.0.4)
|
69
|
+
mime-types (3.1)
|
70
|
+
mime-types-data (~> 3.2015)
|
71
|
+
mime-types-data (3.2016.0521)
|
72
|
+
mini_portile2 (2.2.0)
|
73
|
+
minitest (5.10.3)
|
74
|
+
mocha (1.2.1)
|
75
|
+
metaclass (~> 0.0.1)
|
76
|
+
nokogiri (1.8.0)
|
77
|
+
mini_portile2 (~> 2.2.0)
|
78
|
+
parallel (1.12.0)
|
79
|
+
parser (2.4.0.0)
|
80
|
+
ast (~> 2.2)
|
81
|
+
powerpack (0.1.1)
|
82
|
+
rack (1.6.8)
|
83
|
+
rack-test (0.6.3)
|
84
|
+
rack (>= 1.0)
|
85
|
+
rails (4.2.9)
|
86
|
+
actionmailer (= 4.2.9)
|
87
|
+
actionpack (= 4.2.9)
|
88
|
+
actionview (= 4.2.9)
|
89
|
+
activejob (= 4.2.9)
|
90
|
+
activemodel (= 4.2.9)
|
91
|
+
activerecord (= 4.2.9)
|
92
|
+
activesupport (= 4.2.9)
|
93
|
+
bundler (>= 1.3.0, < 2.0)
|
94
|
+
railties (= 4.2.9)
|
95
|
+
sprockets-rails
|
96
|
+
rails-deprecated_sanitizer (1.0.3)
|
97
|
+
activesupport (>= 4.2.0.alpha)
|
98
|
+
rails-dom-testing (1.0.8)
|
99
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
100
|
+
nokogiri (~> 1.6)
|
101
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
102
|
+
rails-html-sanitizer (1.0.3)
|
103
|
+
loofah (~> 2.0)
|
104
|
+
railties (4.2.9)
|
105
|
+
actionpack (= 4.2.9)
|
106
|
+
activesupport (= 4.2.9)
|
107
|
+
rake (>= 0.8.7)
|
108
|
+
thor (>= 0.18.1, < 2.0)
|
109
|
+
rainbow (2.2.2)
|
110
|
+
rake
|
111
|
+
rake (10.5.0)
|
112
|
+
redis (3.3.3)
|
113
|
+
redis-actionpack (5.0.1)
|
114
|
+
actionpack (>= 4.0, < 6)
|
115
|
+
redis-rack (>= 1, < 3)
|
116
|
+
redis-store (>= 1.1.0, < 1.4.0)
|
117
|
+
redis-activesupport (5.0.3)
|
118
|
+
activesupport (>= 3, < 6)
|
119
|
+
redis-store (~> 1.3.0)
|
120
|
+
redis-rack (2.0.2)
|
121
|
+
rack (>= 1.5, < 3)
|
122
|
+
redis-store (>= 1.2, < 1.4)
|
123
|
+
redis-rails (5.0.2)
|
124
|
+
redis-actionpack (>= 5.0, < 6)
|
125
|
+
redis-activesupport (>= 5.0, < 6)
|
126
|
+
redis-store (>= 1.2, < 2)
|
127
|
+
redis-store (1.3.0)
|
128
|
+
redis (>= 2.2)
|
129
|
+
rspec (3.5.0)
|
130
|
+
rspec-core (~> 3.5.0)
|
131
|
+
rspec-expectations (~> 3.5.0)
|
132
|
+
rspec-mocks (~> 3.5.0)
|
133
|
+
rspec-core (3.5.4)
|
134
|
+
rspec-support (~> 3.5.0)
|
135
|
+
rspec-expectations (3.5.0)
|
136
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
137
|
+
rspec-support (~> 3.5.0)
|
138
|
+
rspec-mocks (3.5.0)
|
139
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
140
|
+
rspec-support (~> 3.5.0)
|
141
|
+
rspec-support (3.5.0)
|
142
|
+
rubocop (0.49.1)
|
143
|
+
parallel (~> 1.10)
|
144
|
+
parser (>= 2.3.3.1, < 3.0)
|
145
|
+
powerpack (~> 0.1)
|
146
|
+
rainbow (>= 1.99.1, < 3.0)
|
147
|
+
ruby-progressbar (~> 1.7)
|
148
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
149
|
+
ruby-progressbar (1.8.1)
|
150
|
+
sprockets (3.7.1)
|
151
|
+
concurrent-ruby (~> 1.0)
|
152
|
+
rack (> 1, < 3)
|
153
|
+
sprockets-rails (3.2.0)
|
154
|
+
actionpack (>= 4.0)
|
155
|
+
activesupport (>= 4.0)
|
156
|
+
sprockets (>= 3.0.0)
|
157
|
+
thor (0.19.4)
|
158
|
+
thread_safe (0.3.6)
|
159
|
+
tzinfo (1.2.3)
|
160
|
+
thread_safe (~> 0.1)
|
161
|
+
unicode-display_width (1.3.0)
|
162
|
+
|
163
|
+
PLATFORMS
|
164
|
+
ruby
|
165
|
+
|
166
|
+
DEPENDENCIES
|
167
|
+
appraisal (~> 2.0)
|
168
|
+
bundler (~> 1.15)
|
169
|
+
bundler-audit (~> 0)
|
170
|
+
mocha (~> 1)
|
171
|
+
rails (= 4.2.9)
|
172
|
+
rake (~> 10.0)
|
173
|
+
redis_set_store!
|
174
|
+
rspec (~> 3.0)
|
175
|
+
rubocop (~> 0)
|
176
|
+
|
177
|
+
BUNDLED WITH
|
178
|
+
1.15.3
|