Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit a275c73

Browse files
Allow more manual lock creation
1 parent ffdf456 commit a275c73

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Locker.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ public function __construct(ClientInterface $redis)
4141
$this->redis = $redis;
4242
}
4343

44+
/**
45+
* Make a new lock instance.
46+
*
47+
* Note that we will not attempt to acquire the lock at this point.
48+
*
49+
* @param string $name
50+
* @param int $timeout
51+
* @param int $play
52+
* @param int $interval
53+
* @param int $trys
54+
*
55+
* @return \AltThree\Locker\Lock
56+
*/
57+
public function make($name, $timeout, $play = 500, $interval = 100, $trys = 128)
58+
{
59+
return new Lock($this->redis, $name, $timeout, $play, $interval, $trys);
60+
}
61+
4462
/**
4563
* Acquire the a lock for, and then excecute the function.
4664
*
@@ -60,7 +78,7 @@ public function __construct(ClientInterface $redis)
6078
*/
6179
public function execute(Closure $function, $name, $timeout, $play = 500, $interval = 100, $trys = 128)
6280
{
63-
$lock = new Lock($this->redis, $name, $timeout, $play, $interval, $trys);
81+
$lock = $this->make($name, $timeout, $play, $interval, $trys);
6482

6583
if (!$lock->acquire()) {
6684
throw new UnableToAcquireLockException("Unable to acquire lock on {$name}.");

0 commit comments

Comments
 (0)