simple_redis_store 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/lib/active_support/cache/simple_redis_store.rb +88 -0
- data/lib/simple_redis_store.rb +2 -0
- data/lib/simple_redis_store/version.rb +3 -0
- data/simple_redis_store.gemspec +20 -0
- metadata +86 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kieran Pilkington
|
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,39 @@
|
|
1
|
+
# Simple Redis Store for ActiveSupport::Cache
|
2
|
+
|
3
|
+
__`simple_redis_store`__ provides a lightweight Redis cache store for ActiveSupport::Cache.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
__`simple_redis_store`__ relies on Redis being installed and running.
|
8
|
+
|
9
|
+
Mac users can install Redis via `brew install redis`.
|
10
|
+
|
11
|
+
Everyone else, check the package manager of your operating system.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile then run `bundle`:
|
16
|
+
|
17
|
+
gem 'simple_redis_store'
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Ruby on Rails
|
22
|
+
|
23
|
+
# config/environments/production.rb
|
24
|
+
config.action_controller.perform_caching = true
|
25
|
+
config.cache_store = :simple_redis_store
|
26
|
+
|
27
|
+
### Standalone
|
28
|
+
|
29
|
+
ActiveSupport::Cache.lookup_store :simple_redis_store
|
30
|
+
|
31
|
+
## TODO
|
32
|
+
|
33
|
+
* Implement multi key retrieval (`def read_multi`)
|
34
|
+
* Improve configuration support
|
35
|
+
* Tests
|
36
|
+
|
37
|
+
## Copyright
|
38
|
+
|
39
|
+
(c) 2012 Kieran Pilkington, release under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'redis'
|
2
|
+
|
3
|
+
# References:
|
4
|
+
# https://github.com/redis/redis-rb/blob/master/lib/redis.rb
|
5
|
+
# https://github.com/jodosha/redis-store/blob/master/redis-activesupport/lib/active_support/cache/redis_store.rb
|
6
|
+
|
7
|
+
module ActiveSupport
|
8
|
+
module Cache
|
9
|
+
class SimpleRedisStore < Store
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
super(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete_matched(matcher, options = nil)
|
16
|
+
instrument(:delete_matched, matcher.inspect) do
|
17
|
+
return unless keys = execute(:keys, matcher)
|
18
|
+
execute(:del, *keys) if keys.any?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def increment(name, amount = 1, options = nil)
|
23
|
+
instrument(:increment, name, :amount => amount) do
|
24
|
+
execute(:incrby, name, amount)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def decrement(name, amount = 1, options = nil)
|
29
|
+
instrument(:decrement, name, :amount => amount) do
|
30
|
+
execute(:decrby, name, amount)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear(options = nil)
|
35
|
+
instrument(:clear, nil, nil) do
|
36
|
+
execute(:flushdb)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def connection(options = {})
|
43
|
+
@redis ||= Redis.new(options)
|
44
|
+
rescue Redis::CannotConnectError
|
45
|
+
@redis = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute(method, *args)
|
49
|
+
return false unless connection
|
50
|
+
connection.send(method, *args)
|
51
|
+
rescue Redis::CannotConnectError
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def key_matcher(pattern, options)
|
56
|
+
if pattern.is_a?(Regexp)
|
57
|
+
raise "Regexps not supported. Use wildcards (*) instead."
|
58
|
+
end
|
59
|
+
|
60
|
+
namespace = options[:namespace]
|
61
|
+
namespace = options[:namespace].call if namespace.is_a?(Proc)
|
62
|
+
[namespace, pattern].compact.join(':')
|
63
|
+
end
|
64
|
+
|
65
|
+
def read_entry(key, options)
|
66
|
+
instrument(:read_entry, key) do
|
67
|
+
return unless entry = execute(:get, key)
|
68
|
+
entry = Marshal.load(entry) rescue entry
|
69
|
+
entry.is_a?(Entry) ? entry : Entry.new(entry)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def write_entry(key, entry, options)
|
74
|
+
instrument(:write_entry, key) do
|
75
|
+
entry = Marshal.dump(entry)
|
76
|
+
execute(:set, key, entry)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete_entry(key, options)
|
81
|
+
instrument(:delete_entry, key) do
|
82
|
+
execute(:del, key)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/simple_redis_store/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kieran Pilkington"]
|
6
|
+
gem.email = ["kieran776@gmail.com"]
|
7
|
+
gem.description = %q{A lightweight Redis cache store for ActiveSupport::Cache}
|
8
|
+
gem.summary = %q{A lightweight Redis cache store for ActiveSupport::Cache}
|
9
|
+
gem.homepage = "https://github.com/KieranP/simple_redis_store"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "simple_redis_store"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SimpleRedisStore::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "activesupport", "~> 3.0"
|
19
|
+
gem.add_runtime_dependency "redis", "~> 3.0.0"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_redis_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kieran Pilkington
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: redis
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
46
|
+
description: A lightweight Redis cache store for ActiveSupport::Cache
|
47
|
+
email:
|
48
|
+
- kieran776@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/active_support/cache/simple_redis_store.rb
|
59
|
+
- lib/simple_redis_store.rb
|
60
|
+
- lib/simple_redis_store/version.rb
|
61
|
+
- simple_redis_store.gemspec
|
62
|
+
homepage: https://github.com/KieranP/simple_redis_store
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A lightweight Redis cache store for ActiveSupport::Cache
|
86
|
+
test_files: []
|