wolverine 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -10
- data/lib/wolverine/path_component.rb +6 -20
- data/lib/wolverine/script.rb +2 -10
- data/lib/wolverine/version.rb +1 -1
- data/lib/wolverine.rb +2 -32
- data/test/integration/wolverine_integration_test.rb +2 -4
- data/test/wolverine/script_test.rb +5 -3
- data/wolverine.gemspec +2 -2
- metadata +50 -37
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -4,14 +4,18 @@ Wolverine is a simple library to allow you to manage and run redis server-side l
|
|
4
4
|
|
5
5
|
Redis versions 2.6 and up allow lua scripts to be run on the server that execute atomically and very quickly.
|
6
6
|
|
7
|
+
This is *extremely* useful.
|
8
|
+
|
7
9
|
Wolverine is a wrapper around that functionality, to package it up in a format more familiar to a Rails codebase.
|
8
10
|
|
9
11
|
## How do I use it?
|
10
12
|
|
11
|
-
1) Make sure you have redis 2.6 or higher installed.
|
13
|
+
1) Make sure you have redis 2.6 or higher installed. As of now, that means compiling from source:
|
12
14
|
|
13
|
-
```
|
14
|
-
redis
|
15
|
+
```shell
|
16
|
+
git clone https://github.com/antirez/redis.git
|
17
|
+
cd redis && make
|
18
|
+
./src/redis-server
|
15
19
|
```
|
16
20
|
|
17
21
|
2) Add wolverine to your Gemfile:
|
@@ -35,13 +39,7 @@ return exists
|
|
35
39
|
4) Call wolverine from your code:
|
36
40
|
|
37
41
|
```ruby
|
38
|
-
Wolverine.util.mexists(
|
39
|
-
```
|
40
|
-
|
41
|
-
Or
|
42
|
-
|
43
|
-
```ruby
|
44
|
-
Wolverine.util.mexists(:keys => ['key1', 'key2', 'key3']) #=> [0, 1, 0]
|
42
|
+
Wolverine.util.mexists('key1', 'key2', 'key3') #=> [0, 1, 0]
|
45
43
|
```
|
46
44
|
|
47
45
|
Methods are available on `Wolverine` paralleling the directory structure
|
@@ -61,3 +59,13 @@ If you want to override one or more of these, doing so in an initializer is reco
|
|
61
59
|
|
62
60
|
For more information on scripting redis with lua, refer to redis' excellent documentation: http://redis.io/commands/eval
|
63
61
|
|
62
|
+
## License
|
63
|
+
|
64
|
+
Copyright (C) 2012 [Shopify](http://shopify.com) by [Burke Libbey](http://burkelibbey.org)
|
65
|
+
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
69
|
+
|
70
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
71
|
+
|
@@ -18,7 +18,6 @@ class Wolverine
|
|
18
18
|
def initialize path, options = {}
|
19
19
|
@path = path
|
20
20
|
@options = options
|
21
|
-
@cache_to = options[:cache_to]
|
22
21
|
@redis = options[:redis] || Wolverine.redis
|
23
22
|
@config = options[:config] || Wolverine.config
|
24
23
|
end
|
@@ -54,19 +53,15 @@ class Wolverine
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def define_directory_method path, sym
|
57
|
-
|
58
|
-
|
59
|
-
cb = proc { dir }
|
60
|
-
define_metaclass_method(sym, &cb)
|
61
|
-
cache_metaclass_method(sym, &cb)
|
56
|
+
dir = PathComponent.new(path, @options)
|
57
|
+
define_metaclass_method(sym) { dir }
|
62
58
|
end
|
63
59
|
|
64
60
|
def define_script_method path, sym, *args
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
cache_metaclass_method(sym, &cb)
|
61
|
+
script = Wolverine::Script.new(path, @options)
|
62
|
+
define_metaclass_method(sym) { |*args|
|
63
|
+
script.call(@redis, *args)
|
64
|
+
}
|
70
65
|
end
|
71
66
|
|
72
67
|
def define_metaclass_method sym, &block
|
@@ -74,15 +69,6 @@ class Wolverine
|
|
74
69
|
metaclass.send(:define_method, sym, &block)
|
75
70
|
end
|
76
71
|
|
77
|
-
def cache_metaclass_method sym, &block
|
78
|
-
unless @cache_to.nil?
|
79
|
-
metaclass = class << @cache_to; self; end
|
80
|
-
metaclass.send(:define_method, sym, &block)
|
81
|
-
cached_methods = @cache_to.send(:cached_methods)
|
82
|
-
cached_methods[sym] = self
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
72
|
end
|
87
73
|
|
88
74
|
end
|
data/lib/wolverine/script.rb
CHANGED
@@ -30,7 +30,6 @@ class Wolverine
|
|
30
30
|
# @raise [LuaError] if the script failed to compile of encountered a
|
31
31
|
# runtime error
|
32
32
|
def call redis, *args
|
33
|
-
t = Time.now
|
34
33
|
begin
|
35
34
|
run_evalsha redis, *args
|
36
35
|
rescue => e
|
@@ -42,26 +41,19 @@ class Wolverine
|
|
42
41
|
else
|
43
42
|
raise
|
44
43
|
end
|
45
|
-
ensure
|
46
|
-
StatsD.measure(statsd_key, (Time.now - t) * 1000, 0.001) if Wolverine.statsd_enabled?
|
47
44
|
end
|
48
45
|
|
49
46
|
private
|
50
47
|
|
51
|
-
def statsd_key
|
52
|
-
k = @file.relative_path_from(Wolverine.config.script_path).to_s.sub!(/\.lua$/,'').gsub!(/\//,'.')
|
53
|
-
"Wolverine.#{k}"
|
54
|
-
end
|
55
|
-
|
56
48
|
def run_evalsha redis, *args
|
57
49
|
instrument :evalsha do
|
58
|
-
redis.evalsha @digest, *args
|
50
|
+
redis.evalsha @digest, args.size, *args
|
59
51
|
end
|
60
52
|
end
|
61
53
|
|
62
54
|
def run_eval redis, *args
|
63
55
|
instrument :eval do
|
64
|
-
redis.eval @content, *args
|
56
|
+
redis.eval @content, args.size, *args
|
65
57
|
end
|
66
58
|
end
|
67
59
|
|
data/lib/wolverine/version.rb
CHANGED
data/lib/wolverine.rb
CHANGED
@@ -23,14 +23,6 @@ class Wolverine
|
|
23
23
|
config.redis
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.statsd_enabled?
|
27
|
-
@statsd_enabled
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.enable_statsd!
|
31
|
-
@statsd_enabled = true
|
32
|
-
end
|
33
|
-
|
34
26
|
# Resets all the scripts cached by Wolverine. Scripts are lazy-loaded and
|
35
27
|
# cached in-memory, so if a file changes on disk, it will be necessary to
|
36
28
|
# manually reset the cache using +reset!+.
|
@@ -38,7 +30,6 @@ class Wolverine
|
|
38
30
|
# @return [void]
|
39
31
|
def self.reset!
|
40
32
|
@root_directory = nil
|
41
|
-
reset_cached_methods
|
42
33
|
end
|
43
34
|
|
44
35
|
# Used to handle dynamic accesses to scripts. Successful lookups will be
|
@@ -67,7 +58,6 @@ class Wolverine
|
|
67
58
|
|
68
59
|
def reset!
|
69
60
|
@root_directory = nil
|
70
|
-
reset_cached_methods
|
71
61
|
end
|
72
62
|
|
73
63
|
def method_missing sym, *args
|
@@ -79,31 +69,11 @@ class Wolverine
|
|
79
69
|
private
|
80
70
|
|
81
71
|
def self.root_directory
|
82
|
-
@root_directory ||= PathComponent.new(config.script_path
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.cached_methods
|
86
|
-
@cached_methods ||= Hash.new
|
87
|
-
end
|
88
|
-
|
89
|
-
def self.reset_cached_methods
|
90
|
-
metaclass = class << self; self; end
|
91
|
-
cached_methods.each_key { |method| metaclass.send(:undef_method, method) }
|
92
|
-
cached_methods.clear
|
72
|
+
@root_directory ||= PathComponent.new(config.script_path)
|
93
73
|
end
|
94
74
|
|
95
75
|
def root_directory
|
96
|
-
@root_directory ||= PathComponent.new(config.script_path, {:
|
97
|
-
end
|
98
|
-
|
99
|
-
def cached_methods
|
100
|
-
@cached_methods ||= Hash.new
|
101
|
-
end
|
102
|
-
|
103
|
-
def reset_cached_methods
|
104
|
-
metaclass = class << self; self; end
|
105
|
-
cached_methods.each_key { |method| metaclass.send(:undef_method, method) }
|
106
|
-
cached_methods.clear
|
76
|
+
@root_directory ||= PathComponent.new(config.script_path, {:config => config, :redis => redis})
|
107
77
|
end
|
108
78
|
|
109
79
|
end
|
@@ -7,10 +7,10 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
|
|
7
7
|
def mock_redis
|
8
8
|
stub.tap do |redis|
|
9
9
|
redis.expects(:evalsha).
|
10
|
-
with('fe24f4dd4ba7881608cca4b846f009195e06d79a', :a, :b).
|
10
|
+
with('fe24f4dd4ba7881608cca4b846f009195e06d79a', 2, :a, :b).
|
11
11
|
raises("NOSCRIPT").once
|
12
12
|
redis.expects(:eval).
|
13
|
-
with(CONTENT, :a, :b).
|
13
|
+
with(CONTENT, 2, :a, :b).
|
14
14
|
returns([1, 0]).once
|
15
15
|
end
|
16
16
|
end
|
@@ -20,7 +20,6 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
|
|
20
20
|
Wolverine.config.script_path = Pathname.new(File.expand_path('../lua', __FILE__))
|
21
21
|
|
22
22
|
assert_equal [1, 0], Wolverine.util.mexists(:a, :b)
|
23
|
-
assert Wolverine.methods.include?(:util)
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_everything_instantiated
|
@@ -29,7 +28,6 @@ class WolverineIntegrationTest < MiniTest::Unit::TestCase
|
|
29
28
|
|
30
29
|
wolverine = Wolverine.new(config)
|
31
30
|
assert_equal [1, 0], wolverine.util.mexists(:a, :b)
|
32
|
-
assert wolverine.methods.include?(:util)
|
33
31
|
end
|
34
32
|
|
35
33
|
end
|
@@ -43,7 +43,7 @@ class Wolverine
|
|
43
43
|
}
|
44
44
|
Wolverine.config.instrumentation = callback
|
45
45
|
redis = Class.new do
|
46
|
-
define_method(:evalsha) do |digest, *args|
|
46
|
+
define_method(:evalsha) do |digest, size, *args|
|
47
47
|
nil
|
48
48
|
end
|
49
49
|
end
|
@@ -53,8 +53,9 @@ class Wolverine
|
|
53
53
|
def test_call_with_cache_hit
|
54
54
|
tc = self
|
55
55
|
redis = Class.new do
|
56
|
-
define_method(:evalsha) do |digest, *args|
|
56
|
+
define_method(:evalsha) do |digest, size, *args|
|
57
57
|
tc.assert_equal DIGEST, digest
|
58
|
+
tc.assert_equal 2, size
|
58
59
|
tc.assert_equal [:a, :b], args
|
59
60
|
end
|
60
61
|
end
|
@@ -67,8 +68,9 @@ class Wolverine
|
|
67
68
|
define_method(:evalsha) do |*|
|
68
69
|
raise "NOSCRIPT No matching script. Please use EVAL."
|
69
70
|
end
|
70
|
-
define_method(:eval) do |content, *args|
|
71
|
+
define_method(:eval) do |content, size, *args|
|
71
72
|
tc.assert_equal CONTENT, content
|
73
|
+
tc.assert_equal 2, size
|
72
74
|
tc.assert_equal [:a, :b], args
|
73
75
|
end
|
74
76
|
end
|
data/wolverine.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Wolverine::VERSION
|
8
8
|
s.authors = ["Burke Libbey"]
|
9
9
|
s.email = ["burke@burkelibbey.org"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = ""
|
11
11
|
s.summary = %q{Wolverine provides a simple way to run server-side redis scripts from a rails app}
|
12
12
|
s.description = %q{Wolverine provides a simple way to run server-side redis scripts from a rails app}
|
13
13
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency 'redis', '>=
|
21
|
+
s.add_runtime_dependency 'redis', '>= 2.2.2'
|
22
22
|
s.add_development_dependency 'mocha', '~> 0.10.5'
|
23
23
|
s.add_development_dependency 'minitest', '~> 2.11.3'
|
24
24
|
s.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,85 +1,96 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wolverine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Burke Libbey
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.2
|
20
|
+
none: false
|
21
|
+
name: redis
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
|
-
|
24
|
+
requirement: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
|
-
- -
|
26
|
+
- - ! '>='
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
28
|
+
version: 2.2.2
|
29
|
+
none: false
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
32
|
requirements:
|
31
|
-
- -
|
33
|
+
- - ~>
|
32
34
|
- !ruby/object:Gem::Version
|
33
35
|
version: 0.10.5
|
36
|
+
none: false
|
37
|
+
name: mocha
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
|
-
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
37
41
|
requirements:
|
38
|
-
- -
|
42
|
+
- - ~>
|
39
43
|
- !ruby/object:Gem::Version
|
40
44
|
version: 0.10.5
|
45
|
+
none: false
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
|
-
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
48
|
requirements:
|
45
|
-
- -
|
49
|
+
- - ~>
|
46
50
|
- !ruby/object:Gem::Version
|
47
51
|
version: 2.11.3
|
52
|
+
none: false
|
53
|
+
name: minitest
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
|
-
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - ~>
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 2.11.3
|
61
|
+
none: false
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
|
-
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- -
|
65
|
+
- - ! '>='
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '0'
|
68
|
+
none: false
|
69
|
+
name: rake
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
|
-
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
65
73
|
requirements:
|
66
|
-
- -
|
74
|
+
- - ! '>='
|
67
75
|
- !ruby/object:Gem::Version
|
68
76
|
version: '0'
|
77
|
+
none: false
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
80
|
requirements:
|
73
|
-
- -
|
81
|
+
- - ! '>='
|
74
82
|
- !ruby/object:Gem::Version
|
75
83
|
version: '0'
|
84
|
+
none: false
|
85
|
+
name: yard
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
|
-
|
88
|
+
requirement: !ruby/object:Gem::Requirement
|
79
89
|
requirements:
|
80
|
-
- -
|
90
|
+
- - ! '>='
|
81
91
|
- !ruby/object:Gem::Version
|
82
92
|
version: '0'
|
93
|
+
none: false
|
83
94
|
description: Wolverine provides a simple way to run server-side redis scripts from
|
84
95
|
a rails app
|
85
96
|
email:
|
@@ -88,8 +99,8 @@ executables: []
|
|
88
99
|
extensions: []
|
89
100
|
extra_rdoc_files: []
|
90
101
|
files:
|
91
|
-
-
|
92
|
-
-
|
102
|
+
- .gitignore
|
103
|
+
- .travis.yml
|
93
104
|
- Gemfile
|
94
105
|
- LICENSE
|
95
106
|
- README.md
|
@@ -113,28 +124,29 @@ files:
|
|
113
124
|
- test/wolverine/script_test.rb
|
114
125
|
- test/wolverine_test.rb
|
115
126
|
- wolverine.gemspec
|
116
|
-
homepage:
|
127
|
+
homepage: ''
|
117
128
|
licenses: []
|
118
|
-
metadata: {}
|
119
129
|
post_install_message:
|
120
130
|
rdoc_options: []
|
121
131
|
require_paths:
|
122
132
|
- lib
|
123
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
134
|
requirements:
|
125
|
-
- -
|
135
|
+
- - ! '>='
|
126
136
|
- !ruby/object:Gem::Version
|
127
137
|
version: '0'
|
138
|
+
none: false
|
128
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
140
|
requirements:
|
130
|
-
- -
|
141
|
+
- - ! '>='
|
131
142
|
- !ruby/object:Gem::Version
|
132
143
|
version: '0'
|
144
|
+
none: false
|
133
145
|
requirements: []
|
134
146
|
rubyforge_project: wolverine
|
135
|
-
rubygems_version:
|
147
|
+
rubygems_version: 1.8.23
|
136
148
|
signing_key:
|
137
|
-
specification_version:
|
149
|
+
specification_version: 3
|
138
150
|
summary: Wolverine provides a simple way to run server-side redis scripts from a rails
|
139
151
|
app
|
140
152
|
test_files:
|
@@ -145,3 +157,4 @@ test_files:
|
|
145
157
|
- test/wolverine/path_component_test.rb
|
146
158
|
- test/wolverine/script_test.rb
|
147
159
|
- test/wolverine_test.rb
|
160
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 8952bd045b5d2197a89aeae601e815c49ec756e7
|
4
|
-
data.tar.gz: 6a78997394c175e29d05d6e857e09d29f2357af9
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: ebafad7f4823374174641a00343317e5c74ef5767b8875355aa2741578a963c797574f3c1b09caf4103fa6bf9340fb6d5e938d9cddc807fce00dbd2b001d1fc3
|
7
|
-
data.tar.gz: 61bd8592eb88dce35a97edd3e7300f8d34fcab300298692d5b2b41269eff18a9f2b946f29a220aad88bf80e07e4cc517d7508ff37404b14e58db93337fa31877
|