簡單實用的redis管理

<?php
header("Content-type: text/html; charset=utf-8");
/* redis test
 *
REDIS_HOST=192.168.99.7
REDIS_PASSWORD=
REDIS_PORT=6379
$redis = new Redis();
$redis->connect($host, $port);
$redis->auth('設置的密碼');
$redis->set('needpassword', '123456');
 * */

//鏈接本地的 Redis 服務
$redis = new Redis();
//$redis->connect('192.168.99.7', 6379);//local test
$redis->connect('101.201.237.201', 6379);//develop test
//$redis->connect('9dde65697f9748fe.m.cnbja.kvstore.aliyuncs.com', 6379);
//$t[]=$redis->auth('Vintop2016');
//$t[] = $redis->getKeys('*');
if (isset($_GET['sel'])){
    $dbindex=intval($_GET['sel']);
    $redis->select($dbindex);
}
$t[] = $redis->getKeys('*');

if (isset($_GET['delv'])) {
    $t[] = $redis->get($_GET['delv']); //bool(false)
    $t[] = $redis->delete($_GET['delv']); //bool(false)
}
if (isset($_GET['del']) && $_GET['del'] == 'del') {
    $redis->flushdb();  # 刪除當前數據庫全部key
    $t[] = $redis->randomkey(); //bool(false)
    $t[] = $redis->getKeys('*');
}
if(isset($_GET['get'])){
  $t[$_GET['v']]=$cr=$redis->get($_GET['get']);
  $t[]=unserialize($cr);
}
$t[] = $redis->getKeys('*');
echo "<pre>";
print_r($t);
相關文章
相關標籤/搜索