正在显示
1 个修改的文件
包含
21 行增加
和
1 行删除
@@ -283,6 +283,7 @@ trait DbQuery { | @@ -283,6 +283,7 @@ 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 | + try { | ||
286 | if(redis()->has($key)){ | 287 | if(redis()->has($key)){ |
287 | $this->cache = 0; | 288 | $this->cache = 0; |
288 | $data = redis()->get($key,$default); | 289 | $data = redis()->get($key,$default); |
@@ -293,12 +294,20 @@ trait DbQuery { | @@ -293,12 +294,20 @@ trait DbQuery { | ||
293 | } | 294 | } |
294 | 295 | ||
295 | } | 296 | } |
297 | + }catch (\Throwable $e){ | ||
298 | + logs($e->getMessage()); | ||
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){ |
348 | + try { | ||
339 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | 349 | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); |
340 | if(redis()->has($key)){ | 350 | if(redis()->has($key)){ |
341 | $this->cache = 0; | 351 | $this->cache = 0; |
342 | return redis()->get($key,[]); | 352 | return redis()->get($key,[]); |
343 | } | 353 | } |
354 | + | ||
355 | + }catch (\Throwable $e){ | ||
356 | + logs($e->getMessage()); | ||
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){ |
364 | + try { | ||
349 | redis()->set($key,$data,$this->cache); | 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; |
-
请 注册 或 登录 后发表评论