redis默認(rèn)是沒有密碼的, 但綁定到本機ip使用,當(dāng)前增加安全要求對redis用密碼訪問ThinkPHP的3.2.3版本 (路徑為 Library\Think\Cache\Driver\Redis.class.php 以及Library\Think\Session\Driver\Red...
redis默認(rèn)是沒有密碼的, 但綁定到本機ip使用,當(dāng)前增加安全要求對redis用密碼訪問
ThinkPHP的3.2.3版本 (路徑為 Library\Think\Cache\Driver\Redis.class.php 以及Library\Think\Session\Driver\Redis.class.php) 的代碼需要補充安全設(shè)定。
構(gòu)造方法需要增加最后三行內(nèi)容public function __construct($options = [])
{
if (!extension_loaded('redis')) {
E(L('_NOT_SUPPORT_') . ':redis');
}
$data_redis_db = C('REDIS_DB');
$options = array_merge([
'host' => C('REDIS_HOST') ?: '127.0.0.1',
'port' => C('REDIS_PORT') ?: 6379,
'timeout' => C('DATA_CACHE_TIMEOUT') ?: false,
'persistent' => false,
'auth' => C('REDIS_AUTH') ? C('REDIS_AUTH') : false,
'db' => empty($data_redis_db) ? 0 : $data_redis_db,
], $options);
$this->options = $options;
$this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME');
$this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX');
$this->options['length'] = isset($options['length']) ? $options['length'] : 0;
$func = $options['persistent'] ? 'pconnect' : 'connect';
$this->handler = new \Redis;
$options['timeout'] === false ?
$this->handler->$func($options['host'], $options['port']) :
$this->handler->$func($options['host'], $options['port'], $options['timeout']);
// 增加代碼,設(shè)置redis安全性,增加認(rèn)證密碼
if (isset($options['auth']) && $options['auth']) {
$this->handler->auth($options['auth']);
}
}
相關(guān)資源:PHP實現(xiàn)Redis單據(jù)鎖以及防止并發(fā)重復(fù)寫入_thinkPHP使用redis防止...
原文來源:https://blog.csdn.net/weixin_33514582/article/details/115622678
來源:本文內(nèi)容搜集或轉(zhuǎn)自各大網(wǎng)絡(luò)平臺,并已注明來源、出處,如果轉(zhuǎn)載侵犯您的版權(quán)或非授權(quán)發(fā)布,請聯(lián)系小編,我們會及時審核處理。
聲明:江蘇教育黃頁對文中觀點保持中立,對所包含內(nèi)容的準(zhǔn)確性、可靠性或者完整性不提供任何明示或暗示的保證,不對文章觀點負(fù)責(zé),僅作分享之用,文章版權(quán)及插圖屬于原作者。
Copyright?2013-2024 JSedu114 All Rights Reserved. 江蘇教育信息綜合發(fā)布查詢平臺保留所有權(quán)利
蘇公網(wǎng)安備32010402000125
蘇ICP備14051488號-3技術(shù)支持:南京博盛藍(lán)睿網(wǎng)絡(luò)科技有限公司
南京思必達(dá)教育科技有限公司版權(quán)所有 百度統(tǒng)計