Created
December 21, 2020 07:16
-
-
Save ThienTranDuy/ec247a9b0eb404ced6a7beaa7019d696 to your computer and use it in GitHub Desktop.
PHP Redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('memory_limit', -1); | |
ini_set('max_execution_time', 0); | |
ini_set("display_errors", 1); | |
ini_set("display_startup_errors", 1); | |
error_reporting(E_ALL); | |
date_default_timezone_set(DefaultValue::$Location); | |
class V1_updateRedis | |
{ | |
// service redis | |
private $_svRedis; | |
public function __construct() | |
{ | |
$this->_svRedis = ConfigRedis::Connect(); | |
$this->_redisBillNumber = NameRedis::_Redis_BillNumber; | |
$this->_redisSubmitIndex = NameRedis::_Redis_SubmitIndex; | |
$this->_redisConfigExtraPrize = NameRedis::_Redis_ConfigExtraPrize; | |
$this->updateConfigExtraPrize(); | |
$this->showAll(); | |
// $this->deleteAll(); | |
$this->_svRedis->close(); | |
} | |
/** | |
* Lấy thông tin keys, list redis. | |
*/ | |
private function showAll() | |
{ | |
try { | |
$redisKeys = $this->_svRedis->getKeys("*"); | |
foreach ($redisKeys as $key) { | |
echo "\n";echo $key;echo "\n"; | |
// key có data tự tạo qua hset | |
if ($key !== $this->_redisConfigExtraPrize) { | |
$list = $this->_svRedis->hgetall($key); | |
print_r($list); | |
} else { | |
// key có data update từ db | |
// $list = $this->_svRedis->hgetall($key); | |
// print_r($list); | |
$list = $this->_svRedis->get($key); | |
print_r(json_decode($list)); | |
} | |
} | |
} catch (Exception $ex) { | |
$msg = "\n Error Job: " . __FILE__ . | |
} | |
} | |
/** | |
* Lấy thông tin keys, list redis. | |
*/ | |
private function deleteAll() | |
{ | |
try { | |
$redisKeys = $this->_svRedis->flushAll(); | |
print_r($redisKeys); | |
} catch (Exception $ex) { | |
$msg = "\n Error Job: " . __FILE__ . | |
"\n Message: " . $ex->getMessage(); | |
$this->_svTelegram->sendMessage($msg); | |
$logErr = "Error: " . $ex->getMessage(); | |
$this->_svLog->WriteLog($this->_pathLog, $logErr); | |
} | |
} | |
/** | |
*/ | |
private function update() | |
{ | |
try { | |
$field = Array('item', 'step', 'amount'); | |
$dataSave = ''; | |
$this->_svRedis->set($this->_redisConfigExtraPrize, json_encode($dataSave)); | |
echo "Update redis success for config extra prize."; | |
echo "\n"; | |
} catch (Exception $ex) { | |
$msg = "\n Error Job: " . __FILE__ . | |
} | |
} | |
} | |
new V1_updateRedis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment