php 将数据库数据缓冲至redis中

/**
     * 轮播图添加至数据库并缓冲至redis中
     *users:闫兵
     *Data:2022/4/21
     *Time:9:46
     */
    public function storeageBanner()
    {
//          获取数据
        $data = Redis::get('www.hyzf.com.homepage.banner');
        if (empty($data)) {
//             查询数据(工厂模式)
            $result = Factory::banner();
//             获取数据
            $isHeat = Banner::$is_heat; 
            $data = $result->where('is_heat', $isHeat)->get();
//             转换为json数据
            $redisrow = json_encode($data);
//            存储redis中
            Redis::setex('www.hyzf.com.homepage.banner', 7200,$redisrow);
        } else {
//             将json数据解密成数组
            $data = json_decode($data, true,256);
        }
        return Msg(200, 'success', $data);
    }

 

 

posted @ 2022-04-21 20:11  王越666  阅读(94)  评论(0编辑  收藏  举报