hyperf 框架 redis 安装和使用

1.安装Redis 的框架扩展

composer require hyperf/redis

2.配置.env文件

REDIS_HOST=127.0.0.1
REDIS_AUTH=Your secret
REDIS_PORT=6379
REDIS_DB=0

3.配置redis.php文件

在项目/config/autoload/,新建一个redis.php文件,文件内容如下

复制代码
<?php
return [
    'default' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'auth' => env('REDIS_AUTH', ''),
        'port' => (int) env('REDIS_PORT', 6379),
        'db' => (int) env('REDIS_DB', 0),
        'cluster' => [
            'enable' => (bool) env('REDIS_CLUSTER_ENABLE', false),
            'name' => null,
            'seeds' => [],
        ],
        'pool' => [
            'min_connections' => 1,
            'max_connections' => 10,
            'connect_timeout' => 10.0,
            'wait_timeout' => 3.0,
            'heartbeat' => -1,
            'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60),
        ],
    ],
];

 

复制代码

4.使用


复制代码

<?php
use Hyperf\Utils\ApplicationContext;

$container = ApplicationContext::getContainer();

$redis = $container->get(\Redis::class);
$result = $redis->keys('*');
复制代码

 

 
posted @ 2021-07-26 16:20  Kris-Q  阅读(1086)  评论(0编辑  收藏  举报