toanppp/php-redis-lock

访问同步机制。

1.1.0 2022-05-19 04:13 UTC

This package is auto-updated.

Last update: 2024-09-18 12:12:17 UTC


README

关于

访问同步机制。

安装

composer require toanppp/php-redis-lock

方法

RedisLock :: getInstance ( string host, int port )

创建或获取 RedisLock 的单例实例。

$redisLockInstance = RedisLock::getInstance('127.0.0.1', 6379);

RedisLock :: acquire ( string key, string | null type = null )

锁定一个键,有无类型均可。

$redisLockInstance->acquire('key');

RedisLock :: release ( string key )

释放一个键。

$redisLockInstance->release('key');

RedisLock :: releaseByType ( string type )

按类型释放一个键。

$type = 'uniqueKey';
$redisLockInstance->acquire(uniqid(), $type);

$redisLockInstance->releaseByType($type);