monster/redislock

simple redis lock

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/monster/redislock

0.1.0 2018-11-24 09:22 UTC

This package is auto-updated.

Last update: 2025-09-25 09:32:57 UTC


README

Build Status Maintainability StyleCI

基于redis的简单分布式锁,只支持单个redis实例,不支持redis集群

安装

composer require monster/redislock

使用

$client = new Predis\Client([
    'scheme' => 'tcp',
    'host'   => '192.168.20.10',
    'port'   => 6379,
]);

$redisLock = new RedisLock\Lock($client);

$result = $redisLock->lock('user:1');
var_dump($result);

$result = $redisLock->isLockReleased('user:1');

$result = $redisLock->release('user:1');
var_dump($result);

方法

<?php
namespace RedisLock;

interface RedisLockInterface
{
    public function lock($key, $ttl);

    public function release($key);

    public function isLockReleased($key, $retry, $sleep);
}