Laravel使用Redis缓存

时间:2020-04-03 06:58:45

标签: laravel caching redis

我想在Laravel中缓存查询。

public function index()
    {
        if (Redis::exists('products')) {
            $products = json_decode(Redis::get('products'));
        } else {
            $products = Product::with('variations.stock')->get();           
            Redis::set('products', json_encode($products));
        }

        return ProductIndexResource::collection($products);

    }

但出现以下错误:

Symfony\Component\Debug\Exception\FatalThrowableError
Call to a member function first() on array

为什么?

0 个答案:

没有答案