PHP code example of rayswoole / redis-pool

1. Go to this page and download the library: Download rayswoole/redis-pool 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/ */

    

rayswoole / redis-pool example snippets


//初始化连接配置
$redisConfig = new \rayswoole\redis\RedisConfig();
//设置最小闲置连接数
$redisConfig->withMin(20);
//设置最大连接数
$redisConfig->withMax(100);
//设置定时器执行频率(毫秒),创建最小空间连接、回收空闲连接
$redisConfig->withIntervalTime(15*1000)
//设置连接可空闲时间
$redisConfig->withIdleTime(30)
//获取连接池对象超时时间, 如果连接池占满在指定时间无法释放新的连接, 将输出Exception, 需要自行捕获
$redisConfig->withTimeout(3.0)
//数据库配置注入
$redisConfig->withExtraConf('redis配置')
//初始化连接池
\rayswoole\redis\facade\Redis::init($redisConfig);

$config = [
    'server' => ['127.0.0.1:6379','....'],//多IP时为cluster模式
    'dbIndex' => 0,//数据库序号, 不建议变更
    'username'=>'',//适用于账号密码认证
    'password'=>'',//适用于账号密码/密码认证
    'prefix' => 'ray_',//key前缀
    'writeOnly' => false,//主服务器是否只写
    'options' => [],
];

use \rayswoole\redis\facade\Redis;
Redis::getInstance()->set('key', 'value');//带编辑器提示
//或者
Redis::set('key', 'value');//不带提示


use rayswoole\redis;
RedisClient::get($redisConfig->getExtraConf());