Why not just lock each id individually? And then check for all requested ids, and bail if there is a lock on any of them
Laravel cache lock(atomic lock),looking for a solution with multiple combination of key
Hi, I am using atomic lock to prevent from processing same task before completing existing one , will help me to get expected output. I implemented cache lock as follows
step1: create a unique regeneratable key with a prefix and service ids(array : numeric, ascending order), used implode to make as a string with hyphen separated, so my lock key look like
prefix: service:1-2-3-4-5
Step2: creating lock like explained in Laravel 8 doc
step3: block
step4: process task
step5: release lock
My problem is in step 1: where a user can make any random combination of array of service ids, for example if I choose two service task with a combination, [1,2] and [1,3].So my cache keys look like
prefix: service:1-2 and prefix: service:1-3
so in this case there is possibility for taking same service id for processing which expected to be locked by previous process of same service id. which leads to a lock ineffectiveness.
for example: if select a task list from DB like:
for 1st combo with service ids 1,2, query will be :
$query->whereIn('id', [1,2]).
for 2nd combo with service ids 1,3, query will be :
$query->whereIn('id', [1,3]).
so there is possibility for getting values of service id 1 and trying to process it by both locking keys
step4 is little long, with multiple selection queries and updating queries
:- its not possible to remove random combination of array, will affect user experience
Is there any solution to solve this problem, it will be very helpful
Thanks in advance
additional details: Laravel version 8.51.0
Please or to participate in this conversation.