Redis locking/task synchronization

32 views
Skip to first unread message

Santos Das

unread,
Jul 14, 2017, 8:39:46 AM7/14/17
to Redis DB

 

How to synchronize among tasks ?

1.  I am using redis cluster

2.  My application is a multi tasked system (has around 8 tasks), each task has its DB interface ( I am using hiredis-vip asynchronous handling)

3.  When my application task receives a message, it fetches the user information record from DB process the message and at the end it writes the record to the DB.

4.  Since mine is a multi tasked system while the task1 is processing the message for one user record at the same time another task may get a might get the request for the same user.

5.  This leads to the problem as when the task2 writes back task1 might have updated the record

 

I am thinking of my design to be like this:

a. What I want to do is when the task1 calls get to get the record, I want to lock the record (basically I want to put the task id of the task which has fetched it). So, when another task fetches it, it gets the record and see that that task1 has locked it , so it forwards the request to task1.

b. This will work but I want my fetch and setting the task id to be atomic.

c.  There will be issues if within the time window of get and set with task id someone else fetches it.

d.  Also, I don’t want to add another transaction for set?

 

Can this be done in one request atomic manner?

 

              a. Basically, when I call get the get sets the passed task id of the record if the field is null, else it returns the value of the task which has locked it.?

 

Any suggestion how this can be solved?

Reply all
Reply to author
Forward
0 new messages