Commit 070b8765 by xmy

fix:配置中心修改

parent bd76587d
...@@ -5,16 +5,18 @@ namespace Hdll\Services\Common\Config; ...@@ -5,16 +5,18 @@ namespace Hdll\Services\Common\Config;
use Swoft\Redis\Redis; use Swoft\Redis\Redis;
use Swoft\App; use Swoft\App;
const CACHE_PREFIX = 'CONFIG_CACHE'; const CACHE_PREFIX = 'CONFIG_CACHE:';
$redis = App::getBean(Redis::class); $redis = App::getBean(Redis::class);
$data = $redis->get(CACHE_PREFIX . 'all'); $data = $redis->get(CACHE_PREFIX . 'all');
if (!empty($data)) { if (empty($data)) {
$db = CfgCenter::dbConnect(); $db = CfgCenter::dbConnect();
$arr = $db->select('config', ['name', 'value']); $arr = $db->select('config', ['name', 'value']);
foreach ($arr as $key=>$value){ foreach ($arr as $key => $value) {
$data[$value['name']] = json_decode($value['value']); $data[$value['name']] = json_decode($value['value'],true);
} }
$redis->set(CACHE_PREFIX . 'all', $data); $redis->set(CACHE_PREFIX . 'all', empty(json_encode($data)) ? $data : json_encode($data));
} else {
$data = json_decode($data, true);
} }
return $data; return $data;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment