From 9b2c70dcc94e4f1144ed0359c2d8fd4900f26d39 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 29 Oct 2024 16:31:51 +0800 Subject: [PATCH] * [refac] trigger error if the key or label is wrong. --- lib/base/mao/mao.class.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/base/mao/mao.class.php b/lib/base/mao/mao.class.php index b1d4d75810..5ec89674f3 100644 --- a/lib/base/mao/mao.class.php +++ b/lib/base/mao/mao.class.php @@ -758,7 +758,8 @@ class baseMao */ public function getByKey(string $key, ...$arguments) { - if(!defined($key)) return false; + if(empty($this->config->cache->keys[$key])) return $this->app->triggerError("The {$key} key is not defined", __FILE__, __LINE__, true); + $cache = $this->config->cache->keys[$key]; if(!empty($cache->fields) && !empty($arguments)) { @@ -797,7 +798,7 @@ class baseMao */ public function save($value) { - if(empty($this->currentKey)) return false; + if(empty($this->currentKey)) return $this->app->triggerError('The current key is empty', __FILE__, __LINE__, true); $this->app->redis->set($this->currentKey, $value); } @@ -812,7 +813,7 @@ class baseMao */ public function setByKey(string $key, $value) { - if(empty($key)) return false; + if(empty($key)) return $this->app->triggerError('The key is empty', __FILE__, __LINE__, true); $this->app->redis->set($key, $value); } @@ -828,8 +829,8 @@ class baseMao */ public function setByLabel(string $label, $value) { - if(empty($label)) return false; - if(empty($this->labels[$label])) return false; + if(empty($label)) return $this->app->triggerError('The label is empty', __FILE__, __LINE__, true); + if(empty($this->labels[$label])) return $this->app->triggerError("The {$label} label is not set", __FILE__, __LINE__, true); $this->app->redis->set($this->labels[$label], $value); }