hyperf 框架 redis 安裝和使用


安裝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;
    }
}

?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM