$redis = new Redis();
        $redis ->connect('127.0.0.1',6379);
        $data = $redis->get('goods_cache');
        if($data){
            echo 'get data from redis<br>';
            $data = json_decode($data,true);
        }else{
            echo 'get data from mysql<br>';
            $data = pdo_fetchall("select id, title from ".tablename('ewei_shop_goods')." where status=1 limit 6");
            $redis->set('goods_cache',json_encode($data));
            $redis->expire('goods_cache',5);//设置缓存时长5秒
        }

        var_dump($data);

 

相关文章:

  • 2021-10-14
  • 2022-12-23
  • 2021-04-09
  • 2021-07-31
  • 2022-12-23
  • 2022-02-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
相关资源
相似解决方案