Skip to content

Commit de05494

Browse files
authored
Merge pull request #1 from rtckit/v2.0.0
v2.0.0
2 parents ab552a2 + 98b28a9 commit de05494

12 files changed

Lines changed: 52 additions & 68 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.editorconfig
12
.phpunit.result.cache
23
reports
34
vendor

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ before_script:
1717
- echo "xdebug.mode=coverage" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
1818

1919
script:
20-
- php -d memory_limit=-1 ./vendor/bin/phpstan analyse -n -vvv --ansi --level=max src
21-
- php -d memory_limit=-1 ./vendor/bin/psalm --show-info=true
22-
- php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
20+
- php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src
21+
- php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true
22+
- php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist --coverage-text --coverage-clover build/logs/clover.xml
2323
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ Asynchronous [Redlock](https://redis.io/topics/distlock) algorithm implementatio
1010

1111
## Quickstart
1212

13-
Once [installed](#installation), you can incorporate Redlock in your projects by instantiating its _Custodian_; this entity is responsible for lock orchestration and it requires access to your process's event loop as well as to a Redis client object instance, e.g.
13+
Once [installed](#installation), you can incorporate Redlock in your projects by instantiating its _Custodian_; this entity is responsible for lock orchestration and it requires access to a Redis client object instance, e.g.
1414

1515
```php
1616
/* Instantiate prerequisites */
17-
$loop = \React\EventLoop\Factory::create();
18-
$factory = new \Clue\React\Redis\Factory($loop);
17+
$factory = new \Clue\React\Redis\Factory(\React\EventLoop\Loop::get());
1918
$client = $factory->createLazyClient('127.0.0.1');
2019

2120
/* Instantiate our lock custodian */
22-
$custodian = new \RTCKit\React\Redlock\Custodian($loop, $client);
21+
$custodian = new \RTCKit\React\Redlock\Custodian($client);
2322
```
2423

2524
#### Acquiring locks
@@ -106,16 +105,16 @@ composer install
106105
Then, go to the project root and run:
107106

108107
```bash
109-
php -d memory_limit=-1 ./vendor/bin/phpunit
108+
php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist
110109
```
111110

112111
### Static Analysis
113112

114113
In order to ensure high code quality, Redlock uses [PHPStan](https://github.com/phpstan/phpstan) and [Psalm](https://github.com/vimeo/psalm):
115114

116115
```sh
117-
php -d memory_limit=-1 ./vendor/bin/phpstan analyse -n -vvv --ansi --level=max src
118-
php -d memory_limit=-1 ./vendor/bin/psalm --show-info=true
116+
php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src
117+
php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true
119118
```
120119

121120
## License

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rtckit/react-redlock",
33
"description": "Asynchronous distributed locks with Redis and ReactPHP",
4-
"version": "1.0.0",
4+
"version": "2.0.0",
55
"type": "library",
66
"keywords": [
77
"lock",
@@ -24,12 +24,13 @@
2424
},
2525
"require": {
2626
"php": ">=7.2",
27-
"clue/redis-react": "^2.0"
27+
"clue/redis-react": "^2.4",
28+
"react/event-loop": "^1.2"
2829
},
2930
"require-dev": {
3031
"phpstan/phpstan": "^0.12",
31-
"phpunit/phpunit": "^9.4",
32-
"vimeo/psalm": "^4.0"
32+
"phpunit/phpunit": "^9.5",
33+
"vimeo/psalm": "^4.9"
3334
},
3435
"autoload": {
3536
"psr-4": {
File renamed without changes.

phpstan.neon renamed to etc/phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ parameters:
22
ignoreErrors:
33
- '#Call to an undefined method Clue\\React\\Redis\\Client::#'
44
includes:
5-
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
5+
- ../vendor/phpstan/phpstan/conf/bleedingEdge.neon
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
<!-- PHPUnit configuration file with new format for PHPUnit 9.3+ -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6-
bootstrap="vendor/autoload.php"
6+
bootstrap="../vendor/autoload.php"
77
colors="true"
88
cacheResult="false">
99
<testsuites>
1010
<testsuite name="reactphp-redlock test suite">
11-
<directory>./tests/</directory>
11+
<directory>../tests/</directory>
1212
</testsuite>
1313
</testsuites>
1414
<coverage>
1515
<include>
16-
<directory>./src/</directory>
16+
<directory>../src/</directory>
1717
</include>
1818
</coverage>
1919
</phpunit>

psalm.xml renamed to etc/psalm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
77
>
88
<projectFiles>
9-
<directory name="src" />
9+
<directory name="../src" />
1010
<ignoreFiles>
11-
<directory name="vendor" />
11+
<directory name="../vendor" />
1212
</ignoreFiles>
1313
</projectFiles>
1414

examples/01-basic.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require(__DIR__ . '/../vendor/autoload.php');
1010

1111
use Clue\React\Redis\Factory as RedisFactory;
12-
use React\EventLoop\Factory as LoopFactory;
12+
use React\EventLoop\Loop;
1313
use React\Promise\PromiseInterface;
1414
use RTCKit\React\Redlock\Custodian;
1515
use RTCKit\React\Redlock\Lock;
@@ -23,14 +23,13 @@
2323
}
2424

2525
/* Instantiate prerequisites */
26-
$loop = LoopFactory::create();
27-
$factory = new RedisFactory($loop);
26+
$factory = new RedisFactory(Loop::get());
2827
$client = $factory->createLazyClient($host);
2928

3029
/* Instantiate our lock custodian */
31-
$custodian = new Custodian($loop, $client);
30+
$custodian = new Custodian($client);
3231

33-
$loop->addTimer(0.001, function () use ($custodian, $loop): void {
32+
Loop::addTimer(0.001, function () use ($custodian): void {
3433
$custodian->acquire('01-basic', 1)
3534
->then(function (?Lock $lock) use ($custodian): PromiseInterface {
3635
if (is_null($lock)) {
@@ -58,11 +57,9 @@
5857
->otherwise(function (Throwable $t): void {
5958
echo "Something bad happened:" . PHP_EOL . " > " . $t->getMessage() . PHP_EOL;
6059
})
61-
->always(function() use ($loop): void {
62-
$loop->stop();
60+
->always(function(): void {
61+
Loop::stop();
6362

6463
echo "Bye!" . PHP_EOL;
6564
});
6665
});
67-
68-
$loop->run();

examples/02-spin.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require(__DIR__ . '/../vendor/autoload.php');
1010

1111
use Clue\React\Redis\Factory as RedisFactory;
12-
use React\EventLoop\Factory as LoopFactory;
12+
use React\EventLoop\Loop;
1313
use React\Promise\PromiseInterface;
1414
use RTCKit\React\Redlock\Custodian;
1515
use RTCKit\React\Redlock\Lock;
@@ -22,15 +22,14 @@
2222
}
2323

2424
/* Instantiate prerequisites */
25-
$loop = LoopFactory::create();
26-
$factory = new RedisFactory($loop);
25+
$factory = new RedisFactory(Loop::get());
2726
$client = $factory->createLazyClient($host);
2827

2928
/* Instantiate our lock custodian */
30-
$custodian = new Custodian($loop, $client);
29+
$custodian = new Custodian($client);
3130

3231
/* First routine to acquire the lock */
33-
$loop->addTimer(0.001, function () use ($custodian): void {
32+
Loop::addTimer(0.001, function () use ($custodian): void {
3433
/* Lock '02-spin' for 5 seconds */
3534
$custodian->acquire('02-spin', 5)
3635
->then(function (?Lock $lock): void {
@@ -46,7 +45,7 @@
4645
});
4746

4847
/* Hopeful routine, attempting to eventually acquire the lock */
49-
$loop->addTimer(1, function ($timer) use ($custodian, $loop): void {
48+
Loop::addTimer(1, function ($timer) use ($custodian): void {
5049
/* Attempt to lock '02-spin', trying up to 7 times with a one second pause between retries.
5150
Once secured, hold the lock for 10 seconds. */
5251
$custodian->spin(7, 1, '02-spin', 10)
@@ -60,11 +59,9 @@
6059
->otherwise(function (Throwable $t): void {
6160
echo "[hopeful] Something bad happened:" . PHP_EOL . " > " . $t->getMessage() . PHP_EOL;
6261
})
63-
->always(function() use ($loop): void {
64-
$loop->stop();
62+
->always(function(): void {
63+
Loop::stop();
6564

6665
echo "Bye!" . PHP_EOL;
6766
});
6867
});
69-
70-
$loop->run();

0 commit comments

Comments
 (0)