正在显示
1 个修改的文件
包含
33 行增加
和
13 行删除
@@ -283,22 +283,31 @@ trait DbQuery { | @@ -283,22 +283,31 @@ trait DbQuery { | ||
283 | private function getCacheData($sql, $default = '', $flag = null){ | 283 | private function getCacheData($sql, $default = '', $flag = null){ |
284 | if($this->cache){ | 284 | if($this->cache){ |
285 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | 285 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); |
286 | - if(redis()->has($key)){ | ||
287 | - $this->cache = 0; | ||
288 | - $data = redis()->get($key,$default); | ||
289 | - if(!$this->cacheNoData){ | ||
290 | - if($data || $data === 0){ | ||
291 | - return $data; | 286 | + try { |
287 | + if(redis()->has($key)){ | ||
288 | + $this->cache = 0; | ||
289 | + $data = redis()->get($key,$default); | ||
290 | + if(!$this->cacheNoData){ | ||
291 | + if($data || $data === 0){ | ||
292 | + return $data; | ||
293 | + } | ||
292 | } | 294 | } |
293 | - } | ||
294 | 295 | ||
296 | + } | ||
297 | + }catch (\Throwable $e){ | ||
298 | + logs($e->getMessage()); | ||
295 | } | 299 | } |
300 | + | ||
296 | } | 301 | } |
297 | $query = $this->query($sql); | 302 | $query = $this->query($sql); |
298 | if($query){ | 303 | if($query){ |
299 | $data = $flag? $query->fetch($flag) : $query->fetch(); | 304 | $data = $flag? $query->fetch($flag) : $query->fetch(); |
300 | if($this->cache){ | 305 | if($this->cache){ |
301 | - redis()->set($key,$data,$this->cache); | 306 | + try { |
307 | + redis()->set($key, $data, $this->cache); | ||
308 | + }catch (\Throwable $e){ | ||
309 | + logs($e->getMessage()); | ||
310 | + } | ||
302 | $this->cache = 0; | 311 | $this->cache = 0; |
303 | } | 312 | } |
304 | return $data; | 313 | return $data; |
@@ -336,17 +345,28 @@ trait DbQuery { | @@ -336,17 +345,28 @@ trait DbQuery { | ||
336 | */ | 345 | */ |
337 | public function all(string|array $sql){ | 346 | public function all(string|array $sql){ |
338 | if($this->cache){ | 347 | if($this->cache){ |
339 | - $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | ||
340 | - if(redis()->has($key)){ | ||
341 | - $this->cache = 0; | ||
342 | - return redis()->get($key,[]); | 348 | + try { |
349 | + $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | ||
350 | + if(redis()->has($key)){ | ||
351 | + $this->cache = 0; | ||
352 | + return redis()->get($key,[]); | ||
353 | + } | ||
354 | + | ||
355 | + }catch (\Throwable $e){ | ||
356 | + logs($e->getMessage()); | ||
343 | } | 357 | } |
358 | + | ||
344 | } | 359 | } |
345 | $query = $this->query($sql); | 360 | $query = $this->query($sql); |
346 | if($query){ | 361 | if($query){ |
347 | $data = $query->fetchAll(); | 362 | $data = $query->fetchAll(); |
348 | if($this->cache){ | 363 | if($this->cache){ |
349 | - redis()->set($key,$data,$this->cache); | 364 | + try { |
365 | + redis()->set($key,$data,$this->cache); | ||
366 | + }catch (\Throwable $e){ | ||
367 | + logs($e->getMessage()); | ||
368 | + } | ||
369 | + | ||
350 | $this->cache = 0; | 370 | $this->cache = 0; |
351 | } | 371 | } |
352 | return $data; | 372 | return $data; |
-
请 注册 或 登录 后发表评论