- 相關(guān)推薦
如何利用PHP訪問(wèn)帶有密碼的Redis
導(dǎo)語(yǔ):如何利用PHP訪問(wèn)帶有密碼的Redis方法,下面小編給大家提供了代碼實(shí)現(xiàn)步驟,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。
一、首先設(shè)置Redis密碼,以提供遠(yuǎn)程登陸
打開(kāi)redis.conf配置文件,找到requirepass,然后修改如下:
requirepass yourpassword
yourpassword就是redis驗(yàn)證密碼,設(shè)置密碼以后發(fā)現(xiàn)可以登陸,但是無(wú)法執(zhí)行命令了。
命令如下:
redis-cli -h 127.0.0.1 -p 6379//啟動(dòng)redis客戶端,并連接服務(wù)器
keys * //輸出服務(wù)器中的所有key
報(bào)錯(cuò)如下
(error) ERR operation not permitted
這時(shí)候你可以用授權(quán)命令進(jìn)行授權(quán),就不報(bào)錯(cuò)了
命令如下:
auth youpassword
二、PHP訪問(wèn)Redis
$redis = new Redis();
$conn = $redis->connect('localhost', 6379);
$auth = $redis->auth('20160601'); //設(shè)置密碼
var_dump($auth);
$redis->set('access_token', "123213213213213213");
$redis->set('expired_time', 1464344863);
var_dump($redis->get("access_token"));
var_dump($redis->get("expired_time"));
【如何利用PHP訪問(wèn)帶有密碼的Redis】相關(guān)文章:
如何使用php操作redis隊(duì)列實(shí)例04-16
php如何生成隨機(jī)密碼07-01
如何給php生成隨機(jī)密碼01-11
php語(yǔ)言redis隊(duì)列操作實(shí)例02-23
php實(shí)現(xiàn)Session存儲(chǔ)到Redis02-15
如何利用PHP語(yǔ)言獲取連接信息05-19