PHPackages                             sdyyf/rlock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. sdyyf/rlock

ActiveLibrary[Caching](/categories/caching)

sdyyf/rlock
===========

redis lock for laravel.

1.0.2(4y ago)3181MITPHPPHP &gt;=7.1

Since May 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/sdyyf/rlock)[ Packagist](https://packagist.org/packages/sdyyf/rlock)[ RSS](/packages/sdyyf-rlock/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

Rlock
=====

[](#rlock)

Redis distributed lock for laravel/lumen

安装
--

[](#安装)

`composer require sdyyf/rlock`

Laravel可通过如下命令发布配置文件

`php artisan vendor:publish --provider="Sdyyf\Rlock\RlockServiceProvider"`

如果你的项目没有vendor:publish命令，需要手动将配置文件复制到config目录下，配置文件路径：\[项目根目录/vendor/sdyyf/rlock/config/rlock.php\]

使用
--

[](#使用)

### 配置

[](#配置)

根据你的项目实际情形，修改 config/rlock.php 配置文件

```
connection  指定使用的redis连接，默认default
prefix      锁名称的统一前缀
lock_config 锁的默认配置
    expire       锁的默认有效时长，即取锁成功后持有锁的时长。单位：秒
    timeout      默认取锁超时的时长，超时放弃，单位：秒。用于自旋锁和排队锁
    sleep        默认自旋重试间隔，单位：毫秒。用于自旋锁重试
    queue_sleep  默认排队重试间隔，单位：毫秒。用于排队锁重试
    max_length   默认最大排队长度，队列已满时放弃排队。设置为0时，不限长度。用于排队锁重试

```

### 示例

[](#示例)

```
/* 简单锁 */
$lock = Rlock::getSimpleLock('lockname', 10);
if ($lock->get()) {
    echo 'get lock succeed.';
} else {
    echo 'get lock failed.'
}

/* 自旋锁 */
$lock = Rlock::getSpinLock('lockname', 10, [
    'timeout' => 10,
    'sleep'   => 100
]);
if ($lock->get()) {
    echo 'get lock succeed.';
} else {
    echo 'get lock failed.'
}

/* 排队锁 */
//使用默认设置
//$lock = Rlock::getQueueLock('lockname', 10);
//使用自定义设置
$lock = Rlock::getQueueLock('lockname', 10, [
    'timeout'    => 10,
    'sleep'      => 100，//不设置该参数时，默认值为lock_config.queue_sleep配置项设定值，注意这里的参数名为sleep
    'max_length' => 10
]);
if ($lock->get()) {
    echo 'get lock succeed.';
} else {
    echo 'get lock failed.'
}

```

#### 回调支持

[](#回调支持)

```
$lock = Rlock::getSimpleLock('lockname', 10);
//result为闭包执行结果，或者获取锁失败返回false
$result = $lock->get(function() {
    //your business logic...
});

```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Total

3

Last Release

1477d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.0

1.0.1PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5136528?v=4)[sdyyf](/maintainers/sdyyf)[@sdyyf](https://github.com/sdyyf)

---

Top Contributors

[![sdyyf](https://avatars.githubusercontent.com/u/5136528?v=4)](https://github.com/sdyyf "sdyyf (9 commits)")

### Embed Badge

![Health badge](/badges/sdyyf-rlock/health.svg)

```
[![Health](https://phpackages.com/badges/sdyyf-rlock/health.svg)](https://phpackages.com/packages/sdyyf-rlock)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[illuminate/cache

The Illuminate Cache package.

12937.0M1.8k](/packages/illuminate-cache)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k90.5k1](/packages/mike-bronner-laravel-model-caching)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21111.6k](/packages/iazaran-smart-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
