mlanett-redis-lock 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Lock
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
data/lib/redis-lock.rb CHANGED
@@ -162,7 +162,7 @@ class Redis
162
162
  return false
163
163
  end
164
164
 
165
- # Calls block until it returns true or times out. Uses exponential backoff.
165
+ # Calls block until it returns true or times out. TODO: Use exponential backoff.
166
166
  # @param block should return true if successful, false otherwise
167
167
  # @returns true if successful, false otherwise
168
168
  def with_timeout( timeout, &block )
@@ -173,7 +173,8 @@ class Redis
173
173
  return true if block.call
174
174
  log :debug, "Timeout" and return false if Time.now + sleepy > expire
175
175
  sleep(sleepy)
176
- sleepy *= 2
176
+ # might like a different strategy, but general goal is not use 100% cpu while contending for a lock.
177
+ # sleepy = [ sleepy * 2, ( expire - Time.now ) / 4 ].min
177
178
  end
178
179
  end
179
180
 
@@ -55,7 +55,7 @@ describe Redis::Lock, redis: true do
55
55
  results = [ false, false, true ]
56
56
  hers.with_timeout(1) { results.shift }.should be_true
57
57
  # this is too many attemps
58
- results = [ false, false, false, false, false, true ]
58
+ results = [ false, false, false, false, false, false, false, false, false, false, true ]
59
59
  hers.with_timeout(1) { results.shift }.should be_false
60
60
  end
61
61
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlanett-redis-lock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000Z
12
+ date: 2012-03-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &70349318263680 !ruby/object:Gem::Requirement
16
+ requirement: &70189385787000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70349318263680
24
+ version_requirements: *70189385787000
25
25
  description: Pessimistic locking using Redis
26
26
  email:
27
27
  - mark.lanett@gmail.com
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 1.8.15
67
+ rubygems_version: 1.8.16
68
68
  signing_key:
69
69
  specification_version: 3
70
70
  summary: Pessimistic locking using Redis