dennis / php-redis-lock
Installs: 6 213
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- predis/predis: 0.8.*
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-12-21 16:30:58 UTC
README
Connecting to Redis:
RedisLock::connect('tcp://host:port');
Or to just connect to localhost and default port:
RedisLock::connect();
Acquiring a Lock:
$lock = RedisLock::lock('resource');
if($lock) {
doSomething();
}
This will attempt to acquire a lock for the named resource. If successful, the return value is a RedisLock object. If the resource was already locked, the return value will be +false+.
Releasing the Lock:
RedisLock::release($lock);
Make sure to release the lock once you're done with it, so another client can acquire it.
Lock Expiration
If your client acquires a lock and then dies before releasing it, the lock will expire after a certain amount of time (default 5 minutes). You can set your own lock expiration when acquiring the lock like so: $lock = RedisLock::lock('resource', $expiration_in_seconds);