首页 > 代码库 > [moka同学笔记]redis练习Demo
[moka同学笔记]redis练习Demo
<?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);
[moka同学笔记]redis练习Demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。