Skip to content

Recognize the lock state of multiple semaphores using the same key #45

@eugenk

Description

@eugenk

When you have many semaphore instances with the same key, only the one that called lock knows that the semaphore is locked, but all of them should find the correct state with locked?. Example of the faulty behavior:

[1] pry(main)> redis_sema = Redis::Semaphore.new(:my_sema)
=> #<Redis::Semaphore:0x007fc6d8c8aae0
 @expiration=nil,
 @name=:my_sema,
 @redis=#<Redis client v3.3.0 for redis://127.0.0.1:6379/0>,
 @resource_count=1,
 @stale_client_timeout=nil,
 @tokens=[],
 @use_local_time=nil>
[2] pry(main)> redis_sema.lock
=> "0"
[3] pry(main)> redis_sema2 = Redis::Semaphore.new(:my_sema)
=> #<Redis::Semaphore:0x007fc6d8b480d8
 @expiration=nil,
 @name=:my_sema2,
 @redis=#<Redis client v3.3.0 for redis://127.0.0.1:6379/0>,
 @resource_count=1,
 @stale_client_timeout=nil,
 @tokens=[],
 @use_local_time=nil>
[4] pry(main)> redis_sema2.locked?
=> false
[5] pry(main)> redis_sema.locked?
=> true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions