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');
编辑于2024-03-13 17:42:49 完善本页 +发起讨论
赞助商
×