PHP code example of msheng / yii2-redlock

1. Go to this page and download the library: Download msheng/yii2-redlock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

msheng / yii2-redlock example snippets



'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,
            ]
        ]
    ]
],


$lock = Yii::$app->redLock->lock('hello');
if($lock){
    sleep(10);
    Yii::$app->redLock->unlock($lock);
}