search

Home  >  Q&A  >  body text

Use redis to design a mechanism to mark a certain data in a locked state

The program goes to the database to read 10 run_status=0 data every time,

When a task is executed, the database updates fields

run_status=-1

indicates that this task is locked.

Of course, after the task execution is completed, run_status=0, indicating that the lock has been unlocked.

Now comes the problem. When executing a task, due to some exception, such as the server suddenly interrupting the program during publishing, run_status=-1 will always be in the locked state. But it's not actually being implemented.

Now you need to design a mechanism to prevent this from happening. What will you do? The current environment can use redis.

迷茫迷茫2732 days ago1245

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-26 10:51:39

    I found this question too simple. Set a key with an expiration time of 60 seconds. Check whether this key exists every time

    reply
    0
  • Cancelreply