ZTBCMSZTBCMS
起步
框架
最佳实践
模块
案例
查看源码
起步
框架
最佳实践
模块
案例
查看源码

Redis

系统提供了统一的 Redis 链接创建和监控。

在config/redis.php中可配置多个 Redis 连接信息

return [
    // 默认使用的连接
    'default' => env('redis.connection', 'default'),

    // 连接配置信息
    'connections' => [
        'default' => [
            'scheme' => env('redis.scheme', 'tcp'), // tcp(推荐),unix,tls
            // scheme = tcp 时 hostname 和 port 必填;或直接 tcp://127.0.0.1:6379
            'host' => env('redis.host', '127.0.0.1'),
            'port' => env('redis.port', 6379),
            'password' => env('redis.password', ''), // 密码

            // scheme = unix 时 path 必填;或直接 unix:///tmp/redis.sock
            //'path' => '/tmp/redis.sock',

            // scheme = tls 时 tls_ca 和 tls_cert 和 tls_key 必填;或直接 tls://127.0.0.1?ssl[cafile]=private.pem&ssl[verify_peer]=true
            //'ssl' => ['cafile' => 'private.pem', 'verify_peer' => true],

            // 数据库序号,通常0~15
            'database' => env('redis.database', 0),
            // 链接超时时间,单位:秒
            'timeout' => env('redis.timeout', 5),
            // 是否持久化
            'persistent' => env('redis.persistent', false),
        ],
    ],
];

获取 Redis 连接实例

use app\common\libs\redis\RedisFactory;

try {
    $redis = RedisFactory::connection($name);
    $info = $redis->info();
} catch (ConnectionException $e) {
    // 连接异常
}

后台连接状态监控

Dashboard

编辑此页
更新于: 2022/6/28 15:09
Contributors: Jayin