This commit is contained in:
hujiabin 2024-08-14 10:45:56 +08:00
parent e4634b23b1
commit 04a32ba926

View File

@ -1,12 +1,11 @@
<?php <?php
use phpcommon\SqlHelper;
class ServerSwitch { class ServerSwitch {
const SERVER_SWITCH_KEY = 'server_switch_redis_key:';
public function getConfig(){ public function getConfig(){
if (!$this->switchConfig){ return $this->getGameSwitch();
$this->initConfig();
}
return $this->switchConfig;
} }
public function heroChainIsOpen(){ public function heroChainIsOpen(){
@ -40,10 +39,35 @@ class ServerSwitch {
return false; return false;
} }
private $switchConfig = null; // private $switchConfig = null;
//
// private function initConfig(){
// $this->switchConfig = getServerSwitchConfig();
// }
private function initConfig(){ public function getGameSwitch(){
$this->switchConfig = getServerSwitchConfig(); $redis = myself()->_getRedis(self::SERVER_SWITCH_KEY);
if ($redis->exists(self::SERVER_SWITCH_KEY)){
$data = json_decode($redis->get(self::SERVER_SWITCH_KEY),true);
}else{
$data = $this->selectSwitchTable();
$redis->set(self::SERVER_SWITCH_KEY,json_encode($data));
$redis->pexpire(self::SERVER_SWITCH_KEY , 10*1000);
}
return $data;
}
private function selectSwitchTable(){
$rows = SqlHelper::ormSelect(myself()->_getConfDbMysql(), 't_game_switch', array());
$data = array();
if (count($rows) > 0){
foreach ($rows as $row){
$data[$row['switch_name']] = $row['is_open'];
}
}else{
$data = getServerSwitchConfig();
}
return $data;
} }
} }