wolverine 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/examples/mexists.lua CHANGED
@@ -1,6 +1,6 @@
1
1
  local exists = {}
2
2
  local existence
3
3
  for _, key in ipairs(KEYS) do
4
- table.insert(exists, redis.call('exists', key))
4
+ table.insert(exists, redis.call('exists', key))
5
5
  end
6
- return exists
6
+ return exists
@@ -0,0 +1,8 @@
1
+ local hash, key, increment
2
+ for i = 1, #KEYS, 3 do
3
+ hash = KEYS[i]
4
+ key = KEYS[i + 1]
5
+ increment = KEYS[i + 2]
6
+ redis.call('hincrby', hash, key, increment)
7
+ end
8
+ return "OK"
@@ -0,0 +1,8 @@
1
+ local hash, key, value
2
+ for i = 1, #KEYS, 3 do
3
+ hash = KEYS[i]
4
+ key = KEYS[i + 1]
5
+ value = KEYS[i + 2]
6
+ redis.call('hset', hash, key, value)
7
+ end
8
+ return "OK"
@@ -0,0 +1,8 @@
1
+ local hash, key, value
2
+ for i = 1, #KEYS, 3 do
3
+ hash = KEYS[i]
4
+ key = KEYS[i + 1]
5
+ value = KEYS[i + 2]
6
+ redis.call('hsetnx', hash, key, value)
7
+ end
8
+ return "OK"
@@ -1,17 +1,27 @@
1
1
  require 'digest/sha1'
2
2
 
3
3
  module Wolverine
4
+ class InvalidScriptError < StandardError ; end
4
5
  class Script
5
6
  attr_reader :content, :digest
6
7
  def initialize file
8
+ @file = file
7
9
  @content = load_lua file
8
10
  @digest = Digest::SHA1.hexdigest @content
9
11
  end
10
12
 
11
13
  def call redis, *args
12
- run_evalsha redis, *args
14
+ begin
15
+ run_evalsha redis, *args
16
+ rescue => e
17
+ e.message =~ /NOSCRIPT/ ? run_eval(redis, *args) : raise
18
+ end
13
19
  rescue => e
14
- e.message =~ /NOSCRIPT/ ? run_eval(redis, *args) : raise
20
+ if e.message =~ /ERR Error (compiling|running) script/
21
+ raise InvalidScriptError, "#{e.message} (in #{@file.inspect})"
22
+ else
23
+ raise
24
+ end
15
25
  end
16
26
 
17
27
  private
@@ -1,3 +1,3 @@
1
1
  module Wolverine
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -14,6 +14,15 @@ module Wolverine
14
14
  @script ||= Wolverine::Script.new('file1')
15
15
  end
16
16
 
17
+ def test_errors_are_better
18
+ assert_raises Wolverine::InvalidScriptError do
19
+ script = Wolverine::Script.new('file1')
20
+ script.instance_variable_set("@content", "asdfasdfasdf+31f")
21
+ script.instance_variable_set("@digest", "79437f5edda13f9c1669b978dd7a9066dd2059f1")
22
+ script.call(Redis.new)
23
+ end
24
+ end
25
+
17
26
  def test_digest_and_content
18
27
  content = "return 1"
19
28
  assert_equal CONTENT, script.content
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolverine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70168248879520 !ruby/object:Gem::Requirement
16
+ requirement: &70212795870940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70168248879520
24
+ version_requirements: *70212795870940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &70168248877840 !ruby/object:Gem::Requirement
27
+ requirement: &70212795869140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70168248877840
35
+ version_requirements: *70212795869140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &70168248876300 !ruby/object:Gem::Requirement
38
+ requirement: &70212795890120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70168248876300
46
+ version_requirements: *70212795890120
47
47
  description: Wolverine provides a simple way to run server-side redis scripts from
48
48
  a rails app
49
49
  email:
@@ -59,6 +59,9 @@ files:
59
59
  - Rakefile
60
60
  - TODO
61
61
  - examples/mexists.lua
62
+ - examples/mhincrby.lua
63
+ - examples/mhmset.lua
64
+ - examples/mhmsetnx.lua
62
65
  - lib/wolverine.rb
63
66
  - lib/wolverine/configuration.rb
64
67
  - lib/wolverine/path_component.rb