PHP code example of uniondrug / redis
1. Go to this page and download the library: Download uniondrug/redis 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/ */
uniondrug / redis example snippets
return [
'default' => [
......
'providers' => [
......
\Uniondrug\Redis\RedisServiceProvider::class,
],
],
];
/**
* Redis配置文件。
*
* lock: 基于Redis的锁功能配置参数,参考如下:
* <code>
* 'lock' => [
* 'retryCount' => 30, // 申请锁的尝试次数
* 'retryDelay' => 500, // 每次申请的最大时间间隔,毫秒
* ],
* </code>
*
* options: Redis服务的配置参数,参考如下:
* <code>
* 'options' => [
* 'prefix' => '', // use custom prefix on all keys
* 'host' => 'localhost',
* 'port' => 6379,
* 'auth' => 'foobared',
* 'persistent' => false, // 持久化连接,默认不持久化
* 'index' => 0,
* ],
* </code>
*/
return [
'default' => [
'lock' => [
'retryCount' => 30, // 申请锁的尝试次数
'retryDelay' => 500, // 每次申请的最大时间间隔,毫秒
],
'options' => [
'prefix' => '_REDIS',
'host' => '127.0.0.1',
'port' => 6379,
'auth' => '',
'persistent' => false,
'index' => 0,
],
],
];
$data = $this->getDI()->getShared('redis')->get($key);
$lock = $this->redisLock->lock('my_resource_name', 1000);
Array
(
[validity] => 9897.3020019531
[resource] => my_resource_name
[token] => 53771bfa1e775
)
$this->redisLock->unlock($lock);