Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors for new redis versions #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
---------

### 0.3.2 February 15, 2022
- Use `redis.exists?` instead of `redis.exists`.
- Fix deprecated calling commands on `Redis` inside `Redis #pipelined`.

### 0.3.1 April 17, 2016
- Fix `sem.lock(0)` bug (thanks eugenk!).

Expand Down
34 changes: 17 additions & 17 deletions lib/redis/semaphore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ def locked?(token = nil)
def signal(token = 1)
token ||= generate_unique_token

@redis.multi do
@redis.hdel grabbed_key, token
@redis.lpush available_key, token
@redis.multi do |transaction|
transaction.hdel grabbed_key, token
transaction.lpush available_key, token

set_expiration_if_necessary
set_expiration_if_necessary(transaction)
end
end

def exists?
@redis.exists(exists_key)
@redis.exists?(exists_key)
end

def all_tokens
@redis.multi do
@redis.lrange(available_key, 0, -1)
@redis.hkeys(grabbed_key)
@redis.multi do |transaction|
transaction.lrange(available_key, 0, -1)
transaction.hkeys(grabbed_key)
end.flatten
end

Expand Down Expand Up @@ -184,23 +184,23 @@ def simple_expiring_mutex(key_name, expires_in)
def create!
@redis.expire(exists_key, 10)

@redis.multi do
@redis.del(grabbed_key)
@redis.del(available_key)
@redis.multi do |transaction|
transaction.del(grabbed_key)
transaction.del(available_key)
@resource_count.times do |index|
@redis.rpush(available_key, index)
transaction.rpush(available_key, index)
end
@redis.set(version_key, API_VERSION)
@redis.persist(exists_key)
transaction.set(version_key, API_VERSION)
transaction.persist(exists_key)

set_expiration_if_necessary
set_expiration_if_necessary(transaction)
end
end

def set_expiration_if_necessary
def set_expiration_if_necessary(transaction)
if @expiration
[available_key, exists_key, version_key].each do |key|
@redis.expire(key, @expiration)
transaction.expire(key, @expiration)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion redis-semaphore.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'redis-semaphore'
s.version = '0.3.1'
s.version = '0.3.2'
s.summary = 'Implements a distributed semaphore or mutex using Redis.'
s.authors = ['David Verhasselt']
s.email = '[email protected]'
Expand Down