码迷,mamicode.com
首页 > 其他好文 > 详细

[moka同学笔记]redis练习Demo

时间:2017-03-14 12:03:29      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:hello   phpstorm   pst   end   creat   mongo   oba   demo1   gen   

 

<?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

标签:hello   phpstorm   pst   end   creat   mongo   oba   demo1   gen   

原文地址:http://www.cnblogs.com/hsd1727728211/p/6547622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!