wv/lock

dev-master 2019-10-22 04:36 UTC

This package is auto-updated.

Last update: 2024-04-22 15:16:42 UTC


README

composer require "wv/lock";

使用

use Wei\Lock\Application;

$config = [
    'cache' => [
        'default' => 'redis',
        'stores' => [
            'file' => [
                 'driver' => 'file',
                 'patch'  => __DIR__ . DIRECTORY_SEPARATOR . 'cache',
            ],
            'memcached' => [
                 'server' => '127.0.0.1',
                 'port'   => 11211,
            ],
            'redis' => [
                 'driver'   => 'predis',
                 'host'     => '127.0.0.1',
                 'password' => null,
                 'port'     => 6379,
                 'database' => 0,
            ],
        ],
    ],
];

$app = new Application($config);

//上锁
try {
    $app->lock->setLock('key', 7200, 0);
} catch (\Exception $e) {
    //捕捉异常
}

//释放锁
$app->lock->releaseLock('key');