Distributed locks with Redis and ReactPHP alternatives and similar libraries
Based on the "Filtering and Validation" category.
Alternatively, view Distributed locks with Redis and ReactPHP alternatives based on common mentions on social networks and blogs.
-
ISO-codes
PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries -
PHP validate
Lightweight and feature-rich PHP validation and filtering library. Support scene grouping, pre-filtering, array checking, custom validators, custom messages. 轻量且功能丰富的PHP验证、过滤库。支持场景分组,前置过滤,数组检查,自定义验证器,自定义消息。 -
Linio Input
Abstracts HTTP request input handling, providing an easy interface for data hydration and validation -
EU VAT Number Validator
:moneybag: A simple and clean PHP library that validates EU VAT registration numbers against the central ec.europa.eu database (using the official europa API) :eu: -
Cake Validation
[READ-ONLY] Validation library from CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp -
DMS Filter
Library that offers Input Filtering based on Annotations for use with Objects. Check out 2.dev for 2.0 pre-release. -
CSV Blueprint
CSV Validator - Strict and automated line-by-line CSV checking tool based on customizable Yaml schemas
SaaSHub - Software Alternatives and Reviews
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Distributed locks with Redis and ReactPHP or a related project?
Popular Comparisons
README
Distributed locks with Redis and ReactPHP
Asynchronous Redlock algorithm implementation for PHP
Quickstart
Once installed, 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.
/* Instantiate prerequisites */
$loop = \React\EventLoop\Factory::create();
$factory = new \Clue\React\Redis\Factory($loop);
$client = $factory->createLazyClient('127.0.0.1');
/* Instantiate our lock custodian */
$custodian = new \RTCKit\React\Redlock\Custodian($loop, $client);
Acquiring locks
For use cases where a binary outcome is desirable, the acquire()
method works best, e.g.:
/**
* @param string $resource Redis key name
* @param float $ttl Lock's time to live (in seconds)
* @param ?string $token Unique identifier for lock in question
* @return PromiseInterface
*/
$custodian->acquire('MyResource', 60, 'r4nd0m_token')
->then(function (?Lock $lock) {
if (is_null($lock)) {
// Ooops, lock could not be acquired for MyResource
} else {
// Awesome, MyResource is locked for a minute
// ...
// Be nice and release the lock when done
$custodian->release($lock);
}
});
Spinlocks
The spin()
method is designed for situations where a process should keep trying acquiring a lock, e.g.
/**
* @param int $attempts Maximum spin/tries
* @param float $interval Spin/try interval (in seconds)
* @param string $resource Redis key name
* @param float $ttl Lock's time to live (in seconds)
* @param ?string $token Unique identifier for lock in question
* @return PromiseInterface
*/
$custodian->spin(100, 0.5, 'HotResource', 10, 'r4nd0m_token')
->then(function (?Lock $lock): void {
if (is_null($lock)) {
// Wow, after 100 tries (with a gap of 0.5 seconds) I've
// given up acquiring a lock on HotResource
} else {
// Awesome, HotResource is locked for 10 seconds
// ...
// Again, be nice and release the lock when done
$custodian->release($lock);
}
})
Lastly, the provided [examples](examples) are a good starting point.
Requirements
Redlock is compatible with PHP 7.2+ and requires the clue/reactphp-redis library.
Installation
You can add the library as project dependency using Composer:
composer require rtckit/react-redlock
If you only need the library during development, for instance when used in your test suite, then you should add it as a development-only dependency:
composer require --dev rtckit/react-redlock
Tests
To run the test suite, clone this repository and then install dependencies via Composer:
composer install
Then, go to the project root and run:
php -d memory_limit=-1 ./vendor/bin/phpunit
Static Analysis
In order to ensure high code quality, Redlock uses PHPStan and Psalm:
php -d memory_limit=-1 ./vendor/bin/phpstan analyse -n -vvv --ansi --level=max src
php -d memory_limit=-1 ./vendor/bin/psalm --show-info=true
License
MIT, see [LICENSE file](LICENSE).
Acknowledgments
- antirez - Original blog post
- ReactPHP Project
- clue/reactphp-redis - Async Redis client implementation
Contributing
Bug reports (and small patches) can be submitted via the issue tracker. Forking the repository and submitting a Pull Request is preferred for substantial patches.
*Note that all licence references and agreements mentioned in the Distributed locks with Redis and ReactPHP README section above
are relevant to that project's source code only.