$redis = new Redis;
$redis->connect('127.0.0.1',6379,0);
//数据库
$host='********';
$user='root';
$psd='****';
$dbname='ask';
$link = mysql_connect($host,$user,$psd);
mysql_select_db($dbname,$link);
mysql_query("set names utf8");
$SQL = "SELECT * FROM question LIMIT 100";
$query = mysql_query($SQL);
$questionName = 'questionName';
while($info = mysql_fetch_array($query)){
$list[] = $info;
$redisName = 'Question_id_'.$info['id'];
$redis->hMset($redisName, $info);
$redis->zAdd($questionName,$info['id'],$info['id']);
$i++;
}
$range = $redis->zRevRange($questionName,0,10); //分页用到的主要函数
foreach($range as $qid){
$pageList[] = $redis->hGetAll('Question_id_'.$qid);
}
print_r($pageList);
?>
|