monster / redislock
simple redis lock
0.1.0
2018-11-24 09:22 UTC
Requires
- php: ^7.1
- predis/predis: ^1.1
Requires (Dev)
- phpspec/phpspec: ^5.1
This package is auto-updated.
Last update: 2024-10-25 07:35:42 UTC
README
基于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); }