I am using the redis cache in Laravel. I have a process that acquires a lock:
Cache::lock('myKey')->get()
That process aborted before releasing the lock.
I have tried running php artisan cache:clear
to release the lock by clearing the entire cache but this does not work.
If I rerun Cache::lock('myKey')->get()
it returns false
because it is still locked.
Also, running Cache::lock('myKey')->release()
does not work because only the process that created it can clear the lock. I could run Cache::lock('myKey')->forceRelease()
to release a lock without respecting its process owner. But I actually have a lot of locks to release.
How to release all locks? Why doesn’t php artisan cache:clear
work?
Because of the way redis works and how Laravel namespaces redis locks running php artisan cache:clear
or Cache::flush()
will not release the locks.
To release all locks you should run redis-cli
then type FLUSHALL
. Then type exit
to leave the redis cli.
$ redis-cli
127.0.0.1:6379> FLUSHALL
OK
127.0.0.1:6379> exit