key not setting in Redis

Viewed 17

I am trying to cache my db records but I cant see it inside my redis keys

My Books models looks like this

class Books extends model implements BookContract{
 public function fetchAll()
    {
        $results = Cache::remember("books_records_cache",1,function(){
            return $this->get();
          });
          return $results;
    }
}

It implements an interface(Contract)

<?php
namespace App\Contracts;
interface BookContract{

  public function fetchAll();
}

and In my controller I am just fetching my records and It should work according to scenario that If key is found it should return those records instead of doing a query to database everytime. Also in my .env I changed cache_driver from file to redis

CACHE_DRIVER=redis

when I hit my route for Books controller I get log one time and insecond time I get Array(0) and If I refresh again it do query again but it shouldn't be doing that BooksController

class BooksController extends Controller
{
  public function show($id)
    {
        DB::connection()->enableQueryLog();
        $books = $this->post->fetchAll();
        $log= DB::getQueryLog();
            print_r($log);
    }}

P.S I have tried setting a random key which was succefull and I am following this video https://www.youtube.com/watch?v=zCMypIqZQzo&list=PLXM5y5j_b0mMdVF5p_2ug_b5tWqah_tfJ&index=4 What Am I missing?

0 Answers
Related