79628440

Date: 2025-05-19 09:21:24
Score: 1
Natty:
Report link

GET_LOCK('lock_name', timeout) is used to lock something by name, so that only one user or program can do a certain task at a time.

RELEASE_LOCK('lock1') removes the lock, so someone else can use it.

SELECT GET_LOCK('lock1', 10);

It tries to get a lock called 'lock1'.

If someone else has it, MySQL waits up to 10 seconds.

if locked return 1 else 0

Imagine a shop where only one cashier can use the register at a time:

One cashier runs GET_LOCK('register', 10) → gets access.

They finish work and run RELEASE_LOCK('register').

Now another cashier can get the lock.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: shani