Class: RedisReadWriteLocks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_read_write_locks/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis, default_ttl: BaseLock::DEFAULT_TTL) ⇒ Client

Returns a new instance of Client.



3
4
5
6
# File 'lib/redis_read_write_locks/client.rb', line 3

def initialize(redis, default_ttl: BaseLock::DEFAULT_TTL)
  @redis = redis
  @default_ttl = default_ttl
end

Instance Method Details

#read_lock(name, ttl: @default_ttl, &block) ⇒ Object



8
9
10
11
# File 'lib/redis_read_write_locks/client.rb', line 8

def read_lock(name, ttl: @default_ttl, &block)
  lock = ReadLock.new(redis: @redis, name: name, ttl: ttl)
  block ? lock.synchronize(&block) : lock
end

#write_lock(name, ttl: @default_ttl, &block) ⇒ Object



13
14
15
16
# File 'lib/redis_read_write_locks/client.rb', line 13

def write_lock(name, ttl: @default_ttl, &block)
  lock = WriteLock.new(redis: @redis, name: name, ttl: ttl)
  block ? lock.synchronize(&block) : lock
end