Laravel - Queues - Unique Job Locks

Behind the scenes, when a ShouldBeUnique job is dispatched, Laravel attempts to acquire a lock with the uniqueId key. If the lock is not acquired, the job is not dispatched. This lock is released when the job completes processing or fails all of its retry attempts. By default, Laravel will use the default cache driver to obtain this lock. However, if you wish to use another driver for acquiring the lock, you may define a uniqueVia method that returns the cache driver that should be used:

    
    use Illuminate\Support\Facades\Cache;
    
    class UpdateSearchIndex implements ShouldQueue, ShouldBeUnique
    {
        ...
    
        /**
         * Get the cache driver for the unique job lock.
         *
         * @return \Illuminate\Contracts\Cache\Repository
         */
        public function uniqueVia()
        {
            return Cache::driver('redis');
        }
    }
	
If you only need to limit the concurrent processing of a job, use the WithoutOverlapping job middleware instead.