PHPackages                             ar414/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ar414/redis-lock

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ar414/redis-lock
================

Redis Pessimistic Lock uses redis keys: setnx, get, getset, del

v1.0.0(6y ago)17562[1 PRs](https://github.com/ar414-com/php-redis-lock/pulls)MITPHPPHP &gt;=5.6.0

Since Mar 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/ar414-com/php-redis-lock)[ Packagist](https://packagist.org/packages/ar414/redis-lock)[ RSS](/packages/ar414-redis-lock/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

RedisLock
=========

[](#redislock)

[![](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)[![](https://camo.githubusercontent.com/3ca8a6f1a562fac3be582c5987a82e63195444980d3443699f2a2eb39b668950/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461626c652d76312e302e302d626c7565)](https://camo.githubusercontent.com/3ca8a6f1a562fac3be582c5987a82e63195444980d3443699f2a2eb39b668950/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461626c652d76312e302e302d626c7565)[![](https://camo.githubusercontent.com/db1cef72adc1f3ec30a189682f558f93119779b3f65a5b5cfc69209f633eb31e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d342e35372532304b422d6f72616e6765)](https://packagist.org/packages/ar414/redis-lock)[![](https://camo.githubusercontent.com/0c967d746eb7f4fe28065a3b94d23faa207cd6f4a968535b20fce0310a87cf89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e)](https://camo.githubusercontent.com/0c967d746eb7f4fe28065a3b94d23faa207cd6f4a968535b20fce0310a87cf89/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d677265656e)[![](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)

PHP use Redis Pessimistic Lock uses redis keys: setnx, get, getset, del

Install
=======

[](#install)

```
composer require ar414/redis-lock

```

Usage
=====

[](#usage)

### New instance

[](#new-instance)

```
use Ar414\RedisLock;

$redis = new \Redis();
$redis->connect('127.0.0.1','6379');

$lockTimeOut = 5;
$redisLock = new RedisLock($redis,$lockTimeOut);
```

### Get Lock

[](#get-lock)

```
$lockKey = 'lock:user:wallet:uid:1001';
$lockExpire = $redisLock->getLock($lockKey);
if(!$lockExpire || $lockExpire < time()){
    throw new \Exception('Busy Lock');
}
//TODO：Business logic
```

### Release Lock

[](#release-lock)

```
$redisLock->releaseLock($lockKey,$lockExpire);

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

2244d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1207372c90c00c433ecfbc3d2a02f4138cd88d1f951ef5fee527ec8751b71bfe?d=identicon)[ar414](/maintainers/ar414)

---

Top Contributors

[![jimmybytes](https://avatars.githubusercontent.com/u/58111015?v=4)](https://github.com/jimmybytes "jimmybytes (5 commits)")

### Embed Badge

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

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

PHPackages © 2026

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