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文件,文件内容如下
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.使用
use Hyperf\Utils\ApplicationContext;
$container = ApplicationContext::getContainer();
$redis = $container->get(\Redis::class);
$result = $redis->keys('*');
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文件,文件内容如下
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.使用
use Hyperf\Utils\ApplicationContext;
$container = ApplicationContext::getContainer();
$redis = $container->get(\Redis::class);
$result = $redis->keys('*');