PHPackages                             purelightme/redis-lock - 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. purelightme/redis-lock

ActiveLibrary[Caching](/categories/caching)

purelightme/redis-lock
======================

Redis分布式锁,串行任务

v1.2(5y ago)12901MITPHP

Since Nov 30Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Purelightme/redis-lock)[ Packagist](https://packagist.org/packages/purelightme/redis-lock)[ RSS](/packages/purelightme-redis-lock/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

### Redis-Lock 分布式锁

[](#redis-lock-分布式锁)

- 使用lua原子操作，更安全
- 支持redis集群
- 支持自动续期(多进程实现，类似 java redisson 的 watch dog)

### Install

[](#install)

```
composer require purelightme/redis-lock

```

### Test

[](#test)

```
php test/run.php

```

### Demo

[](#demo)

> 若不想要自动续期功能，可直接使用 RedisLock 类手动控制加锁释放锁

```
$config = [
    'host' => 'redis',
    'name' => 'default',
    'ttl' => 60,//原子锁ttl
    'interval' => 5,//子进程自动续期周期
    //...其他predis支持的参数
];

try{
    $res = SequenceTask::execute($config,function (){
        //fake long time logic...
        sleep(20);
        return 'job execute success';
    });
}catch (InternalException $exception){
    //一般情况下无需关注
    $res = $exception->getMessage();
}catch (Throwable $exception){
    //任务执行中本身的异常，需要关注
    $res = $exception->getMessage();
}

var_dump($res);
```

### Requirement

[](#requirement)

- pcntl 扩展
- posix 扩展(可选)

### 使用场景

[](#使用场景)

- 订单超时自动取消
- 定时生成系统报表数据
- crontab任务【可100%避免任务重叠导致的问题】
- ......

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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 ~1 days

Total

3

Last Release

2038d ago

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/purelightme-redis-lock/health.svg)

```
[![Health](https://phpackages.com/badges/purelightme-redis-lock/health.svg)](https://phpackages.com/packages/purelightme-redis-lock)
```

###  Alternatives

[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[rhubarbgroup/redis-cache

A persistent object cache backend for WordPress powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI.

527101.4k1](/packages/rhubarbgroup-redis-cache)[symfony-bundles/redis-bundle

Symfony Redis Bundle

291.2M7](/packages/symfony-bundles-redis-bundle)[millipress/millicache

WordPress Full-Page Cache based on Rules &amp; Flags. Delivers flexible, scalable caching workflows backed by Redis and ValKey in-memory stores.

722.9k2](/packages/millipress-millicache)[pdffiller/qless-php

PHP Bindings for qless

29113.7k2](/packages/pdffiller-qless-php)[lion/bundle

Lion-framework configuration and initialization package

122.3k4](/packages/lion-bundle)

PHPackages © 2026

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