Redis semaphore for the semaphore that works across multiple worker processes

·

1 min read

The Concurrent::Semaphore is a part of the concurrent-ruby gem and provides a basic in-process semaphore implementation. However, it cannot be directly used with Redis or its shared memory, as it is designed for thread synchronization within the same process rather than across multiple processes.

To create a semaphore that works across multiple processes using Redis, you can use the redis-semaphore gem, as I mentioned earlier. The redis-semaphore gem allows you to create a semaphore that is backed by Redis, making it accessible to multiple worker processes.

Overall, if there is only one worker process, Concurrent::Semaphore should be used to be accessed from all threads in the worker process. However, redis should be introduced to create a semaphore that works across multiple worker processes.