Module: RedisLocks

Defined in:
lib/redis_locks.rb,
lib/redis_locks/mutex.rb,
lib/redis_locks/version.rb,
lib/redis_locks/semaphore.rb,
lib/redis_locks/token_bucket.rb,
lib/redis_locks/evalsha_or_eval.rb,
lib/redis_locks/resource_unavailable.rb

Defined Under Namespace

Classes: AlreadyLocked, Mutex, RateLimitExceeded, ResourceUnavailable, Semaphore, SemaphoreUnavailable, TokenBucket

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.evalsha_or_eval(redis:, script:, digest:, keys: [], args: []) ⇒ Object

This ensures that each Lua script is evaluated at most once; after it has been evaluated, we will be able to call it just by passing its digest.



5
6
7
8
9
10
11
12
13
# File 'lib/redis_locks/evalsha_or_eval.rb', line 5

def self.evalsha_or_eval(redis:, script:, digest:, keys: [], args: [])
  redis.evalsha digest, keys, args
rescue Redis::CommandError => e
  if e.message.start_with?('NOSCRIPT')
    redis.eval script, keys, args
  else
    raise
  end
end

.redisObject



14
15
16
17
# File 'lib/redis_locks.rb', line 14

def self.redis
  raise "RedisLocks.redis is not set!" unless @redis
  @redis
end

.redis=(redis) ⇒ Object



10
11
12
# File 'lib/redis_locks.rb', line 10

def self.redis=(redis)
  @redis = redis
end