redis-lock 0.1.1 → 0.1.2

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.
@@ -1,5 +1,5 @@
1
1
  module Redis
2
2
  module Lock
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -46,12 +46,12 @@ class Redis
46
46
  end
47
47
 
48
48
  raise RedisLockException.new("Unable to acquire lock for #{key}.")
49
- rescue => e
49
+ rescue Exception => e
50
50
  if e.message == "Unable to acquire lock for #{key}."
51
+ attempt_counter += 1
51
52
  if attempt_counter == max_attempts
52
53
  raise
53
54
  else
54
- attempt_counter += 1
55
55
  sleep 1
56
56
  retry
57
57
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'redis-lock'
3
3
  require 'logger'
4
+ require 'date'
4
5
 
5
6
  describe 'redis' do
6
7
 
@@ -56,5 +57,13 @@ describe 'redis' do
56
57
  @redis.lock_for_update('test_key', 9000) { @redis.set('test_key', 'awesome') }
57
58
  @redis.get('lock:test_key').should be_nil
58
59
  end
60
+
61
+ it "should keep trying to lock a key" do
62
+ time = DateTime.now
63
+ @redis.lock('test_key', 9000)
64
+ lambda { @redis.lock('test_key', 9000, 10) }.should raise_exception("Unable to acquire lock for test_key.")
65
+ # Should have spent 9 seconds trying to lock
66
+ DateTime.now.should >= time + Rational(9, 86400)
67
+ end
59
68
 
60
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-lock
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-23 00:00:00.000000000 Z
12
+ date: 2013-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis