kvstorage 버그 수정

This commit is contained in:
2018-05-21 00:23:50 +09:00
parent d0778550ab
commit 7776b35cab
5 changed files with 25 additions and 10 deletions
+1 -1
View File
@@ -1496,7 +1496,7 @@ function updateOnline() {
} }
//접속중인 국가 //접속중인 국가
$gameStor->online = $onlinenume; $gameStor->online = $onlinenum;
$gameStor->onlinenation = $onnationstr; $gameStor->onlinenation = $onnationstr;
} }
+1
View File
@@ -46,6 +46,7 @@ function processSpring() {
function processGoldIncome() { function processGoldIncome() {
$db = DB::db(); $db = DB::db();
$connect=$db->get(); $connect=$db->get();
$gameStor = new KVStorage($db, 'game_env');
$admin = $gameStor->getValues(['year','month','gold_rate']); $admin = $gameStor->getValues(['year','month','gold_rate']);
$adminLog = []; $adminLog = [];
+2 -2
View File
@@ -140,10 +140,10 @@ class ChangeCity extends \sammo\Event\Action{
if($targetType == 'cities'){ if($targetType == 'cities'){
if(is_numeric($this->targetArgs)){ if(is_numeric($this->targetArgs)){
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE city IN (%ls)', $this->targetArgs); return DB::db()->queryFirstColumn('SELECT city FROM city WHERE city IN %ls', $this->targetArgs);
} }
else{ else{
return DB::db()->queryFirstColumn('SELECT city FROM city WHERE name IN (%ls)', $this->targetArgs); return DB::db()->queryFirstColumn('SELECT city FROM city WHERE name IN %ls', $this->targetArgs);
} }
} }
+19 -7
View File
@@ -138,6 +138,9 @@ class KVStorage{
} }
public function getValuesAsArray(array $keys, bool $onlyCache=false): array{ public function getValuesAsArray(array $keys, bool $onlyCache=false): array{
if(!$keys){
return [];
}
$dictResult = $this->getValues($keys, $onlyCache); $dictResult = $this->getValues($keys, $onlyCache);
$result = []; $result = [];
foreach($keys as $key){ foreach($keys as $key){
@@ -147,6 +150,9 @@ class KVStorage{
} }
public function getValues(array $keys, bool $onlyCache=false): array{ public function getValues(array $keys, bool $onlyCache=false): array{
if(!$keys){
return [];
}
if ($this->cacheData === null) { if ($this->cacheData === null) {
return $this->getDBValues($keys); return $this->getDBValues($keys);
} }
@@ -224,7 +230,11 @@ class KVStorage{
} }
private function getDBValues(array $keys): array{ private function getDBValues(array $keys): array{
if(!$keys){
return [];
}
$result = []; $result = [];
$keys = array_map('strval', $keys);
foreach($this->db->queryAllLists( foreach($this->db->queryAllLists(
'SELECT `key`, `value` FROM %b WHERE `namespace`=%s AND `key` IN %ls', 'SELECT `key`, `value` FROM %b WHERE `namespace`=%s AND `key` IN %ls',
$this->tableName, $this->tableName,
@@ -243,6 +253,7 @@ class KVStorage{
} }
private function getDBValue($key){ private function getDBValue($key){
$key = (string)$key;
$value = $this->db->queryFirstField( $value = $this->db->queryFirstField(
'SELECT `value` FROM %b WHERE `namespace`=%s AND `key`=%s', 'SELECT `value` FROM %b WHERE `namespace`=%s AND `key`=%s',
$this->tableName, $this->tableName,
@@ -268,17 +279,18 @@ class KVStorage{
} }
private function deleteDBValue($key):self{ private function deleteDBValue($key):self{
$this->db->delete($this->tableName, [ $key = (string)$key;
'namespace'=>$this->storNamespace, $this->db->delete(
'key'=>$key $this->tableName,
]); '`namespace`=%s AND `key`=%s',
$this->storNamespace,
$key
);
return $this; return $this;
} }
private function resetDBNamespace():self{ private function resetDBNamespace():self{
$this->db->delete($this->tableName, [ $this->db->delete($this->tableName, 'namespace=%s', $this->storNamespace);
'namespace'=>$this->storNamespace
]);
return $this; return $this;
} }
} }
+2
View File
@@ -646,6 +646,8 @@ class MeekroDB {
)); ));
} }
echo $sql."<br>\n";
if ($this->throw_exception_on_error) { if ($this->throw_exception_on_error) {
$e = new MeekroDBException($db->error, $sql, $db->errno); $e = new MeekroDBException($db->error, $sql, $db->errno);
throw $e; throw $e;