Skip to content

Commit d2e7caf

Browse files
committed
FLAG_DO_NOT_THROW_EXCEPTIONS
1 parent df365b1 commit d2e7caf

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ $Redis = ClientFactory::create([
5757
*/
5858
function updateJsonInRedis(RedisClient $Redis, $key, array $array) {
5959
// Create new Lock instance
60-
$Lock = new RedisLock($Redis, 'Lock_'.$key, RedisLock::FLAG_CATCH_EXCEPTIONS);
60+
$Lock = new RedisLock($Redis, 'Lock_'.$key, RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS);
6161

6262
// Acquire lock for 2 sec.
6363
// If lock has acquired in another thread then we will wait 3 second,
@@ -102,22 +102,22 @@ Create a new instance of RedisLock.
102102
1. RedisClient **$Redis** - Instanse of [RedisClient](https://github.com/cheprasov/php-redis-client)
103103
2. string **$key** - name of key in Redis storage. Only locks with the same name will compete with each other for lock.
104104
3. int **$flags**, default = 0
105-
* `RedisLock::FLAG_CATCH_EXCEPTIONS` - use this flag, if you don't want catch exceptions by yourself. Do not use this flag, if you want have a full control on situation with locks. Default behavior without this flag - all Exceptions will be thrown.
105+
* `RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS` - use this flag, if you don't want catch exceptions by yourself. Do not use this flag, if you want have a full control on situation with locks. Default behavior without this flag - all Exceptions will be thrown.
106106

107107
##### Example
108108

109109
```php
110110
$Lock = new RedisLock($Redis, 'lockName');
111111
// or
112-
$Lock = new RedisLock($Redis, 'lockName', RedisLock::FLAG_CATCH_EXCEPTIONS);
112+
$Lock = new RedisLock($Redis, 'lockName', RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS);
113113

114114
```
115115

116116
#### `bool` RedisLock :: acquire ( `int|float` **$lockTime** , [ `float` **$waitTime** = 0 [, `float` **$sleep** = 0.005 ] ] )
117117
---
118118
Try to acquire lock for `$lockTime` seconds.
119119
If lock has acquired in another thread then we will wait `$waitTime` seconds, until another thread release the lock.
120-
Otherwise method throws a exception (if `FLAG_CATCH_EXCEPTIONS` is not set) or result.
120+
Otherwise method throws a exception (if `FLAG_DO_NOT_THROW_EXCEPTIONS` is not set) or result.
121121
Returns `true` on success or `false` on failure.
122122

123123
##### Method Pameters

src/RedisLock/RedisLock.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ class RedisLock implements LockInterface {
2222
const VERSION = '1.0.1';
2323

2424
/**
25+
* @deprecated
26+
* @see FLAG_DO_NOT_THROW_EXCEPTIONS
2527
* Catch Lock exceptions and return false or null as result
2628
*/
2729
const FLAG_CATCH_EXCEPTIONS = 1;
2830

31+
/**
32+
* Do not throw exception, return false or null as result
33+
*/
34+
const FLAG_DO_NOT_THROW_EXCEPTIONS = 1;
35+
2936
/**
3037
* Sleep time between wait iterations, in seconds
3138
*/

test/Integration/RedisLockTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function test_RedisLock() {
113113

114114
public function test_RedisLock_WithoutExceptions() {
115115
$key = static::TEST_KEY;
116-
$RedisLock = new RedisLock(static::$Redis, $key, RedisLock::FLAG_CATCH_EXCEPTIONS);
116+
$RedisLock = new RedisLock(static::$Redis, $key, RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS);
117117

118118
$this->assertFalse($RedisLock->acquire(RedisLock::LOCK_MIN_TIME * 0.9));
119119
$this->assertTrue($RedisLock->acquire(self::LOCK_MIN_TIME * 2));

test/Unit/RedisLockTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ public function testMethod_isFlagExist() {
6868
$RedisLock = new RedisLock($this->getRedis(), $key);
6969
$this->assertSame(false, $Method->invoke(
7070
$RedisLock,
71-
RedisLock::FLAG_CATCH_EXCEPTIONS
71+
RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS
7272
));
7373

7474
$RedisLock = new RedisLock(
7575
$this->getRedis(), $key,
76-
RedisLock::FLAG_CATCH_EXCEPTIONS
76+
RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS
7777
);
7878
$this->assertSame(true, $Method->invoke(
7979
$RedisLock,
80-
RedisLock::FLAG_CATCH_EXCEPTIONS
80+
RedisLock::FLAG_DO_NOT_THROW_EXCEPTIONS
8181
));
8282
}
8383

0 commit comments

Comments
 (0)