# redis锁 **Repository Path**: leruge/redis-lock ## Basic Information - **Project Name**: redis锁 - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-28 - **Last Updated**: 2026-02-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # redis 锁 > thinkphp8 redis锁,需要添加redis信息到缓存配置文件 ## 安装 1. `composer require leruge/redlock` ## 使用前配置 1. 在 `config/cache.php` 中添加 `redis` 链接,参考官方文档即可 ```php 'redis' => [ 'type' => 'redis', 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', 'select' => 0, 'timeout' => 0, 'expire' => 0, 'persistent' => false, 'prefix' => '', 'tag_prefix' => 'tag:', 'serialize' => [], 'fail_delete' => false, ] ``` ## 提供方法 1. 获取锁 2. 释放锁 ### 获取锁 1. 实例化 `(new \leruge\Lock())->getLock($lockKey, $requestId, $isNegative = true, $expireTime = 15000)` ### 释放锁 1. 实例化 `(new \leruge\Lock())->releaseLock($lockKey, $requestId)` ### 参数说明 1. `$lockKey` 锁标识 2. `$requestId` 锁标识值,建议使用唯一值,比如uuid 3. `$isNegative` 是否悲观锁,默认true 4. `$expireTime` 锁过期时间,默认15000,15秒