| 
...
 | 
...
 | 
@@ -283,6 +283,7 @@ trait DbQuery { | 
| 
 | 
 | 
     private function getCacheData($sql, $default = '', $flag = null){
 | 
| 
 | 
 | 
         if($this->cache){
 | 
| 
 | 
 | 
             $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
 | 
| 
 | 
 | 
             try {
 | 
| 
 | 
 | 
                 if(redis()->has($key)){
 | 
| 
 | 
 | 
                     $this->cache = 0;
 | 
| 
 | 
 | 
                     $data =  redis()->get($key,$default);
 | 
| 
...
 | 
...
 | 
@@ -293,12 +294,20 @@ trait DbQuery { | 
| 
 | 
 | 
                     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
             }catch (\Throwable $e){
 | 
| 
 | 
 | 
                 logs($e->getMessage());
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
         $query = $this->query($sql);
 | 
| 
 | 
 | 
         if($query){
 | 
| 
 | 
 | 
             $data = $flag? $query->fetch($flag) :  $query->fetch();
 | 
| 
 | 
 | 
             if($this->cache){
 | 
| 
 | 
 | 
                 redis()->set($key,$data,$this->cache);
 | 
| 
 | 
 | 
                 try {
 | 
| 
 | 
 | 
                     redis()->set($key, $data, $this->cache);
 | 
| 
 | 
 | 
                 }catch (\Throwable $e){
 | 
| 
 | 
 | 
                     logs($e->getMessage());
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
                 $this->cache = 0;
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             return $data;
 | 
| 
...
 | 
...
 | 
@@ -336,17 +345,28 @@ trait DbQuery { | 
| 
 | 
 | 
      */
 | 
| 
 | 
 | 
     public function all(string|array $sql){
 | 
| 
 | 
 | 
         if($this->cache){
 | 
| 
 | 
 | 
             try {
 | 
| 
 | 
 | 
                 $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql));
 | 
| 
 | 
 | 
                 if(redis()->has($key)){
 | 
| 
 | 
 | 
                     $this->cache = 0;
 | 
| 
 | 
 | 
                     return redis()->get($key,[]);
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
             }catch (\Throwable $e){
 | 
| 
 | 
 | 
                 logs($e->getMessage());
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
         $query = $this->query($sql);
 | 
| 
 | 
 | 
         if($query){
 | 
| 
 | 
 | 
             $data = $query->fetchAll();
 | 
| 
 | 
 | 
             if($this->cache){
 | 
| 
 | 
 | 
                 try {
 | 
| 
 | 
 | 
                     redis()->set($key,$data,$this->cache);
 | 
| 
 | 
 | 
                 }catch (\Throwable $e){
 | 
| 
 | 
 | 
                     logs($e->getMessage());
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
                 $this->cache = 0;
 | 
| 
 | 
 | 
             }
 | 
| 
 | 
 | 
             return $data;
 | 
...
 | 
...
 | 
 |