Skip to content

Commit

Permalink
Run redis calls inside block (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturictus authored May 25, 2023
1 parent 815bed7 commit 32a8543
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 1 addition & 7 deletions lib/sidekiq_alive/redis/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ def delete(key)
end

def ttl(...)
redis.ttl(...)
end

private

def redis
Sidekiq.redis { |r| r }
Sidekiq.redis { |redis| redis.ttl(...) }
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/sidekiq_alive/redis/redis_client_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ module Redis
# https://github.com/redis-rb/redis-client
class RedisClientGem < Base
def set(key, time:, ex:)
redis.call("SET", key, time, ex: ex)
Sidekiq.redis { |redis| redis.call("SET", key, time, ex: ex) }
end

def get(key)
redis.call("GET", key)
Sidekiq.redis { |redis| redis.call("GET", key) }
end

def match(key)
redis.scan("MATCH", key).map { |key| key }
Sidekiq.redis { |redis| redis.scan("MATCH", key).map { |key| key } }
end

def delete(key)
redis.call("DEL", key)
Sidekiq.redis { |redis| redis.call("DEL", key) }
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/sidekiq_alive/redis/redis_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def match(key)
def delete(key)
redis.del(key)
end

private

def redis
Sidekiq.redis { |redis| redis }
end
end
end
end

0 comments on commit 32a8543

Please sign in to comment.