monster/redislock

simple redis lock

0.1.0 2018-11-24 09:22 UTC

This package is auto-updated.

Last update: 2024-11-25 07:47:25 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);
}