readis 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/readis.rb +29 -1
  2. metadata +3 -3
data/lib/readis.rb CHANGED
@@ -7,6 +7,33 @@ require "term/ansicolor"
7
7
 
8
8
  class Readis
9
9
 
10
+ class Retry
11
+ def initialize(client)
12
+ @client = client
13
+ @backoff = 1
14
+ end
15
+
16
+ def method_missing(name, *args, &block)
17
+ begin
18
+ @client.send(name, *args, &block)
19
+ @backoff = 1
20
+ rescue => e
21
+ puts "Command failed because of error: #{e.message}"
22
+ puts "Sleeping #{@backoff} seconds"
23
+ sleep @backoff
24
+ if @backoff <= 8
25
+ @backoff = @backoff * 2
26
+ end
27
+ retry
28
+ end
29
+ end
30
+
31
+ def type(*args)
32
+ @client.send(:type, *args)
33
+ end
34
+
35
+ end
36
+
10
37
  def self.command_runner(name)
11
38
  case name
12
39
  when "inspect"
@@ -23,7 +50,8 @@ class Readis
23
50
 
24
51
  def initialize
25
52
  self.parser.parse!
26
- @redis = Redis.new(:host => self.options[:host], :port => self.options[:port])
53
+ @_redis = Redis.new(:host => self.options[:host], :port => self.options[:port])
54
+ @redis = Retry.new(@_redis)
27
55
  end
28
56
 
29
57
  def options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-18 00:00:00.000000000 Z
13
+ date: 2013-03-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redis
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 1.8.24
112
+ rubygems_version: 1.8.23
113
113
  signing_key:
114
114
  specification_version: 3
115
115
  summary: Read-only Redis Utilities