Redis

Redis用法与数据库类似,例如 plugin/foo/config/redis.php

return [
    'default' => [
        'host' => '127.0.0.1',
        'password' => null,
        'port' => 6379,
        'database' => 0,
    ],
    'cache' => [
        'host' => '127.0.0.1',
        'password' => null,
        'port' => 6379,
        'database' => 1,
    ],
];

使用时

use support\Redis;
Redis::connection('plugin.foo.default')->get('key');
Redis::connection('plugin.foo.cache')->get('key');

同样的,如果想复用主项目的Redis配置

use support\Redis;
Redis::get('key');
// 假设主项目还配置了一个cache连接
Redis::connection('cache')->get('key');
编辑于2023-02-21 09:28:27 完善本页 +发起讨论
赞助商
QQ交流群 865805921