Download the PHP package pudongping/hyperf-wise-locksmith without Composer
On this page you can find all versions of the php package pudongping/hyperf-wise-locksmith. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pudongping/hyperf-wise-locksmith
More information about pudongping/hyperf-wise-locksmith
Files in pudongping/hyperf-wise-locksmith
Package hyperf-wise-locksmith
Short Description A mutex library provider for the Hyperf framework, designed to enable serialized execution of PHP code in high-concurrency scenarios.
License MIT
Homepage https://github.com/pudongping/hyperf-wise-locksmith
Informations about the package hyperf-wise-locksmith
License
hyperf-wise-locksmith
[](https://packagist.org/packages/pudongping/hyperf-wise-locksmith) [](https://packagist.org/packages/pudongping/hyperf-wise-locksmith) [](https://packagist.org/packages/pudongping/hyperf-wise-locksmith) [](https://php.net/) [](https://github.com/pudongping/hyperf-wise-locksmith) [](https://packagist.org/packages/pudongping/hyperf-wise-locksmith)
English | 中文
:lock: A mutex library provider for the Hyperf framework, designed to enable serialized execution of PHP code in high-concurrency scenarios. This library is based on pudongping/wise-locksmith.
Requirements
- PHP >= 8.1
- hyperf ~3.1.0
Installation
Branches or tags
Branch
- 2.2: For hyperf 2.2
- 3.0: For hyperf ~3.0
- 3.1: For hyperf ~3.1
Tag
- 1.0.x: For hyperf 2.2
- 2.0.x: For hyperf 3.0
- 3.0.x: For hyperf 3.1
Quickstart
Below, an example of deducting user balances in a high-concurrency scenario will be provided to demonstrate the functionality and usage of this library.
Create the app\Controller\BalanceController.php
file and write the following code:
Next, create the app\Services\AccountBalanceService.php
file and write the following code:
When we access the /balance/consumer?type=noMutex
URL, we can observe that the user's balance goes negative, which is clearly illogical. However, when we visit the following URLs, we can see that the user's balance is not going negative, demonstrating effective protection of the accuracy of shared resources in a race condition.
/balance/consumer?type=flock
: File lock/balance/consumer?type=redisLock
: Distributed lock/balance/consumer?type=redLock
: Redlock/balance/consumer?type=channelLock
: Coroutine-level mutex
Note
Regarding the use of redisLock
and redLock
:
- When using
redisLock
, it defaults to using the firstkey
configuration in theconfig/autoload/redis.php
configuration file, which corresponds to the default Redis instance. You can optionally pass the fourth parameterstring|null $redisPoolName
to re-specify a different Redis instance as needed. - When using
redLock
, it defaults to using all thekey
configurations in theconfig/autoload/redis.php
configuration file. You can optionally pass the fourth parameter?array $redisPoolNames = null
to re-specify different Redis instances as needed.
Documentation
You can find detailed documentation for pudongping/wise-locksmith.
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.
License
MIT, see LICENSE file.
All versions of hyperf-wise-locksmith with dependencies
hyperf/logger Version ~3.1.0
hyperf/redis Version ~3.1.0
pudongping/wise-locksmith Version ^1.0