redis-store-rails2-compat 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redis-store-rails2-compat.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Kimmo Lehto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kimmo Lehto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Redis-store 1.x Rails2 compatibility
2
+
3
+ The old 1.0.0.1 version of [redis-store](https://github.com/redis-store/redis-store) gem used to work nicely for people still on Rails2. It however depends on an antique version of (redis)[https://github.com/redis/redis-rb] Gem.
4
+
5
+ Versions after 1.1 dropped all direct support for rails/merb/sinatra and you would end up with
6
+ ```ruby
7
+ uninitialized constant ActiveSupport::Cache::RedisStore
8
+ ```
9
+
10
+ This gem will restore the ActiveSupport extensions from the 1.0 versions to redis-store ~1.1.4.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'redis-store-rails2-compat'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install redis-store-rails2-compat
25
+
26
+ ## Usage
27
+
28
+ Require 'redis-store-rails2-compat' in environment.rb or config/initializers/ and thats' it. If you had 1.0.0.1 working, with this you can upgrade to 1.1.4.
29
+
30
+ ## Contributors
31
+
32
+ * Kimmo Lehto ([@kke](https://github.com/kke)
33
+ * Matt Horan ([@mhoran](https://github.com/mhoran)) (original redis-store)
34
+ * Luca Guidi ([http://lucaguidi.com](http://lucaguidi.com) (original redis-store)
35
+
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,186 @@
1
+ module ActiveSupport
2
+ module Cache
3
+ class RedisStore < Store
4
+ # Instantiate the store.
5
+ #
6
+ # Example:
7
+ # RedisStore.new
8
+ # # => host: localhost, port: 6379, db: 0
9
+ #
10
+ # RedisStore.new "example.com"
11
+ # # => host: example.com, port: 6379, db: 0
12
+ #
13
+ # RedisStore.new "example.com:23682"
14
+ # # => host: example.com, port: 23682, db: 0
15
+ #
16
+ # RedisStore.new "example.com:23682/1"
17
+ # # => host: example.com, port: 23682, db: 1
18
+ #
19
+ # RedisStore.new "example.com:23682/1/theplaylist"
20
+ # # => host: example.com, port: 23682, db: 1, namespace: theplaylist
21
+ #
22
+ # RedisStore.new "localhost:6379/0", "localhost:6380/0"
23
+ # # => instantiate a cluster
24
+ def initialize(*addresses)
25
+ @data = ::Redis::Store::Factory.create(addresses)
26
+ super()
27
+ end
28
+
29
+ def write(name, value, options = nil)
30
+ options = merged_options(options)
31
+ instrument(:write, name, options) do |payload|
32
+ entry = options[:raw].present? ? value : Entry.new(value, options)
33
+ write_entry(namespaced_key(name, options), entry, options)
34
+ end
35
+ end
36
+
37
+ # Delete objects for matched keys.
38
+ #
39
+ # Example:
40
+ # cache.del_matched "rab*"
41
+ def delete_matched(matcher, options = nil)
42
+ options = merged_options(options)
43
+ instrument(:delete_matched, matcher.inspect) do
44
+ matcher = key_matcher(matcher, options)
45
+ begin
46
+ !(keys = @data.keys(matcher)).empty? && @data.del(*keys)
47
+ rescue Errno::ECONNREFUSED => e
48
+ false
49
+ end
50
+ end
51
+ end
52
+
53
+ # Reads multiple keys from the cache using a single call to the
54
+ # servers for all keys. Options can be passed in the last argument.
55
+ #
56
+ # Example:
57
+ # cache.read_multi "rabbit", "white-rabbit"
58
+ # cache.read_multi "rabbit", "white-rabbit", :raw => true
59
+ def read_multi(*names)
60
+ values = @data.mget(*names)
61
+
62
+ # Remove the options hash before mapping keys to values
63
+ names.extract_options!
64
+
65
+ result = Hash[names.zip(values)]
66
+ result.reject!{ |k,v| v.nil? }
67
+ result
68
+ end
69
+
70
+ # Increment a key in the store.
71
+ #
72
+ # If the key doesn't exist it will be initialized on 0.
73
+ # If the key exist but it isn't a Fixnum it will be initialized on 0.
74
+ #
75
+ # Example:
76
+ # We have two objects in cache:
77
+ # counter # => 23
78
+ # rabbit # => #<Rabbit:0x5eee6c>
79
+ #
80
+ # cache.increment "counter"
81
+ # cache.read "counter", :raw => true # => "24"
82
+ #
83
+ # cache.increment "counter", 6
84
+ # cache.read "counter", :raw => true # => "30"
85
+ #
86
+ # cache.increment "a counter"
87
+ # cache.read "a counter", :raw => true # => "1"
88
+ #
89
+ # cache.increment "rabbit"
90
+ # cache.read "rabbit", :raw => true # => "1"
91
+ def increment(key, amount = 1)
92
+ instrument(:increment, key, :amount => amount) do
93
+ @data.incrby key, amount
94
+ end
95
+ end
96
+
97
+ # Decrement a key in the store
98
+ #
99
+ # If the key doesn't exist it will be initialized on 0.
100
+ # If the key exist but it isn't a Fixnum it will be initialized on 0.
101
+ #
102
+ # Example:
103
+ # We have two objects in cache:
104
+ # counter # => 23
105
+ # rabbit # => #<Rabbit:0x5eee6c>
106
+ #
107
+ # cache.decrement "counter"
108
+ # cache.read "counter", :raw => true # => "22"
109
+ #
110
+ # cache.decrement "counter", 2
111
+ # cache.read "counter", :raw => true # => "20"
112
+ #
113
+ # cache.decrement "a counter"
114
+ # cache.read "a counter", :raw => true # => "-1"
115
+ #
116
+ # cache.decrement "rabbit"
117
+ # cache.read "rabbit", :raw => true # => "-1"
118
+ def decrement(key, amount = 1)
119
+ instrument(:decrement, key, :amount => amount) do
120
+ @data.decrby key, amount
121
+ end
122
+ end
123
+
124
+ # Clear all the data from the store.
125
+ def clear
126
+ instrument(:clear, nil, nil) do
127
+ @data.flushdb
128
+ end
129
+ end
130
+
131
+ def stats
132
+ @data.info
133
+ end
134
+
135
+ # Force client reconnection, useful Unicorn deployed apps.
136
+ def reconnect
137
+ @data.reconnect
138
+ end
139
+
140
+ protected
141
+ def write_entry(key, entry, options)
142
+ method = options && options[:unless_exist] ? :setnx : :set
143
+ @data.send method, key, entry, options
144
+ rescue Errno::ECONNREFUSED => e
145
+ false
146
+ end
147
+
148
+ def read_entry(key, options)
149
+ entry = @data.get key, options
150
+ if entry
151
+ entry.is_a?(ActiveSupport::Cache::Entry) ? entry : ActiveSupport::Cache::Entry.new(entry)
152
+ end
153
+ rescue Errno::ECONNREFUSED => e
154
+ nil
155
+ end
156
+
157
+ ##
158
+ # Implement the ActiveSupport::Cache#delete_entry
159
+ #
160
+ # It's really needed and use
161
+ #
162
+ def delete_entry(key, options)
163
+ @data.del key
164
+ rescue Errno::ECONNREFUSED => e
165
+ false
166
+ end
167
+
168
+
169
+ # Add the namespace defined in the options to a pattern designed to match keys.
170
+ #
171
+ # This implementation is __different__ than ActiveSupport:
172
+ # __it doesn't accept Regular expressions__, because the Redis matcher is designed
173
+ # only for strings with wildcards.
174
+ def key_matcher(pattern, options)
175
+ prefix = options[:namespace].is_a?(Proc) ? options[:namespace].call : options[:namespace]
176
+ if prefix
177
+ raise "Regexps aren't supported, please use string with wildcards." if pattern.is_a?(Regexp)
178
+ "#{prefix}:#{pattern}"
179
+ else
180
+ pattern
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+
@@ -0,0 +1,3 @@
1
+ require 'redis-store'
2
+ require 'active_support'
3
+ require 'active_support/cache/redis_store'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "redis-store-rails2-compat"
7
+ spec.version = '1.1.4'
8
+ spec.authors = ["Kimmo Lehto"]
9
+ spec.email = ["kimmo.lehto@gmail.com"]
10
+ spec.description = %q{Bring back the rails2 compatibility from redis-store 1.0.0.1 to 1.1.x}
11
+ spec.summary = %q{Bring back the rails2 compatibility from redis-store 1.0.0.1 to 1.1.x}
12
+ spec.homepage = "https://github.com/kke/redis-store-rails2-compat"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "redis-store", "<2.0"
21
+ spec.add_runtime_dependency "activesupport", "<3.0"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-store-rails2-compat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 4
10
+ version: 1.1.4
11
+ platform: ruby
12
+ authors:
13
+ - Kimmo Lehto
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2014-05-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 2
29
+ - 0
30
+ version: "2.0"
31
+ name: redis-store
32
+ prerelease: false
33
+ type: :runtime
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - <
40
+ - !ruby/object:Gem::Version
41
+ hash: 7
42
+ segments:
43
+ - 3
44
+ - 0
45
+ version: "3.0"
46
+ name: activesupport
47
+ prerelease: false
48
+ type: :runtime
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 9
57
+ segments:
58
+ - 1
59
+ - 3
60
+ version: "1.3"
61
+ name: bundler
62
+ prerelease: false
63
+ type: :development
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ name: rake
76
+ prerelease: false
77
+ type: :development
78
+ requirement: *id004
79
+ description: Bring back the rails2 compatibility from redis-store 1.0.0.1 to 1.1.x
80
+ email:
81
+ - kimmo.lehto@gmail.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files: []
87
+
88
+ files:
89
+ - .gitignore
90
+ - Gemfile
91
+ - LICENSE
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/active_support/cache/redis_store.rb
96
+ - lib/redis-store-rails-2-compat.rb
97
+ - redis-store-rails2-compat.gemspec
98
+ homepage: https://github.com/kke/redis-store-rails2-compat
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.25
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Bring back the rails2 compatibility from redis-store 1.0.0.1 to 1.1.x
131
+ test_files: []
132
+