Skip to content

Commit cb33f3e

Browse files
authored
Merge pull request #4 from cheprasov/v102
V102
2 parents df365b1 + d0b6d1b commit cb33f3e

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Latest Stable Version](https://poser.pugx.org/cheprasov/php-redis-lock/v/stable)](https://packagist.org/packages/cheprasov/php-redis-lock)
33
[![Total Downloads](https://poser.pugx.org/cheprasov/php-redis-lock/downloads)](https://packagist.org/packages/cheprasov/php-redis-lock)
44

5-
# RedisLock v1.0.1 for PHP >= 5.5
5+
# RedisLock v1.0.2 for PHP >= 5.5
66

77
## About
88
RedisLock for PHP is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy. Based on [redis](http://redis.io/).
@@ -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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cheprasov/php-redis-lock",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "RedisLock for PHP is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy.",
55
"homepage": "http://github.com/cheprasov/php-redis-lock",
66
"minimum-stability": "stable",

src/RedisLock/RedisLock.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@
1919

2020
class RedisLock implements LockInterface {
2121

22-
const VERSION = '1.0.1';
22+
const VERSION = '1.0.2';
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)