Skip to content

Commit

Permalink
made compatible with ruby 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Phillips committed May 20, 2016
1 parent c4396ea commit 7f9562a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/redlock/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def initialize(servers = DEFAULT_REDIS_URLS, options = {})
# +extend+: A lock ("lock_info") to extend.
# +block+:: an optional block to be executed; after its execution, the lock (if successfully
# acquired) is automatically unlocked.
def lock(resource, ttl, extend: nil, &block)
def lock(resource, ttl, options={}, &block)
extend = options[:extend] || nil
lock_info = try_lock_instances(resource, ttl, extend)

if block_given?
Expand Down Expand Up @@ -86,10 +87,10 @@ def unlock(lock_info)
# Locks a resource, executing the received block only after successfully acquiring the lock,
# and returning its return value as a result.
# See Redlock::Client#lock for parameters.
def lock!(*args, **keyword_args)
def lock!(*args)
fail 'No block passed' unless block_given?

lock(*args, **keyword_args) do |lock_info|
lock(*args) do |lock_info|
raise LockError, 'failed to acquire lock' unless lock_info
return yield
end
Expand Down
5 changes: 5 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@
lock_manager.lock!(resource_key, ttl) { fail } rescue nil
expect(resource_key).to be_lockable(lock_manager, ttl)
end

it 'passes the extension parameter' do
my_lock_info = lock_manager.lock(resource_key, ttl)
expect{ lock_manager.lock!(resource_key, ttl, extend: my_lock_info){} }.to_not raise_error
end
end

context 'when lock is not available' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Coveralls.wear!
require 'redlock'

LOCK_INFO_KEYS = %i{validity resource value}
LOCK_INFO_KEYS = [:validity, :resource, :value]

RSpec::Matchers.define :be_lock_info_for do |resource|
def correct_type?(actual)
Expand Down

0 comments on commit 7f9562a

Please sign in to comment.