安裝Redis 的框架擴張
composer require hyperf/redis
配置redis的參數 -> .env文件中
REDIS_HOST=127.0.0.1 REDIS_AUTH=Fl REDIS_PORT=6379 REDIS_DB=0
在模型文件中
<?php declare(strict_types=1); namespace App\Model\Data; use App\Model\Entity\IndexModel; use Hyperf\Redis\Redis; use Hyperf\Utils\ApplicationContext; class IndexData { private $redis; public function IndexDataTest(){ $IndexModel = new IndexModel(); $container = ApplicationContext::getContainer(); $redis = $container->get(\Redis::class); $result = $redis->keys('*'); print_r($result); $res = $IndexModel->IndexModelTest(); return $res; } } ?>