<?php /** * Created by PhpStorm. * User: moka同学 * Date: 2017/3/13 * Time: 10:54 */ echo 'Hello redis'.'<br>'; $redis = new Redis(); $redis->connect("127.0.0.1","6379"); //demo1 /*$redis->set("name","This is firewater!"); echo $redis->get("name");*/ //demo2 /*$redis->set('tutorial-name','redis tutorial'); echo "test:".$redis->get('tutorial-name');*/ //list /*$redis->lPush('demo-list','Redis'); $redis->lPush('demo-list','Mongodb'); $redis->lPush('demo-list','mysql'); $arList = $redis->lRange('demo-list',0,5); echo '保存的demo-list:'.'<br>'; print_r($arList);*/ /*$aList = $redis->keys("*"); echo '保存'.'<br>'; print_r($aList);*/ //hash类型 /*$redis->delete('people'); $redis->hSet('people','name','mingming'); $redis->hSet('people','age',25); $redis->hSet('people','gender',1); $val = $redis->hGet('people','age'); var_dump($val); $val = $redis->hMGet('people',array('name','age')); var_dump($val);*/ //sort set 类型,排行榜 $redis->delete('name'); $redis->zAdd('name',100,'xiaoming'); $redis->zAdd('name',90,'xiaohong'); $redis->zAdd('name',96,'xiaobai'); $val = $redis->zRange('name',0,-1); //从低到高 var_dump($val); $val = $redis->zRevRange('name',0,-1);//从高到低 var_dump($val);