文章目录
- composer require hyperf/redis
- 在config/autoload/redis.php下<?php return [ 'default' => [ 'host' => env('REDIS_HOST', 'localhost'), 'auth' => env('REDIS_AUTH', null), 'port' => (int) env('REDIS_PORT', 6379), 'db' => (int) env('REDIS_DB', 0), '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), ], ], ];
- <?php namespace AppController;class IndexController extends AbstractController { public function index() { // 从容器里拿出Redis对象 redis = HyperfUtilsApplicationContext::getContainer()->get(HyperfRedisRedis::class); // 使用redis returnredis->keys('*'); } }
composer require hyperf/redis
composer require hyperf/redis
- 在
config/autoload/redis.php下 
<?php
return [
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'auth' => env('REDIS_AUTH', null),
'port' => (int) env('REDIS_PORT', 6379),
'db' => (int) env('REDIS_DB', 0),
'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),
],
],
];
config/autoload/redis.php下 
<?php
return [
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'auth' => env('REDIS_AUTH', null),
'port' => (int) env('REDIS_PORT', 6379),
'db' => (int) env('REDIS_DB', 0),
'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),
],
],
];
<?php
namespace AppController;
class IndexController extends AbstractController
{
public function index()
{
// 从容器里拿出Redis对象
redis = HyperfUtilsApplicationContext::getContainer()->get(HyperfRedisRedis::class);
// 使用redis
returnredis->keys('*');
}
}
<?php
namespace AppController;
class IndexController extends AbstractController
{
public function index()
{
// 从容器里拿出Redis对象
redis = HyperfUtilsApplicationContext::getContainer()->get(HyperfRedisRedis::class);
// 使用redis
returnredis->keys('*');
}
}


