msheng / yii2-redlock
Class for easier Redlock integration
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- signe/redlock-php: ~1.0.0
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2025-01-05 02:25:55 UTC
README
A redlock for Yii2, distributed locks with Redis
Based on Redlock-rb by Salvatore Sanfilippo and signe redlock-php
Installation
To install run:
composer require "msheng/yii2-redlock:~1.0.0"
Or add this line to require section of composer.json:
"msheng/yii2-redlock": "~1.0.0"
project
Your project need to be an yii2-app-advanced , and here is the guide
main.php
In common/config/main.php or main-local.php
<?php 'components' => [ 'redLock' => [ 'class' => 'msheng\RedLock\RedLock', 'servers' => [ [ 'hostname' => '127.0.0.1', 'port' => 6379, 'timeout' => 0.5, ], [ 'hostname' => '127.0.0.1', 'port' => 6389, 'timeout' => 0.05, ], [ 'hostname' => '127.0.0.1', 'port' => 6399, 'timeout' => 0.05, ] ] ] ],
Usage
<?php $lock = Yii::$app->redLock->lock('hello'); if($lock){ sleep(10); Yii::$app->redLock->unlock($lock); }