public function RedisdDbOne() {
2 // 清空Redis数据库
3 Redis::
flushall();
4
5
6 // redis的string类型
7 Redis::set("laravel","Hello woshi laravel"
);
8 dump(Redis::get("laravel"
)) ;
9
10
11 // redis的哈希类型
12 Redis::hmset(‘happy:huizhou‘,[‘name‘=>"惠州"
]);
13 Redis::hmset("fail:xiaoshou",
[
14 "lover" => "黑嘿嘿??",
15 ‘nice‘ => "我是xiaoshou",
16 ‘挑衅‘ => ‘来打我啊‘
17 ]);
18 dump(Redis::hgetall("happy:huizhou"
));
19 dump(Redis::hgetall(‘fail:xiaoshou‘
));
20 echo "<br/><hr/>"
;
21
22
23 // redis的无序列表
24 Redis::sAdd(‘huizhou‘,[‘小东‘,‘小追命‘,‘小龙女‘
]);
25 Redis::sAdd(‘xiaoshou‘,[‘小明‘,‘小追命‘,‘阳光宅猫‘
]);
26 #获取无序集合
27 dump(Redis::smembers(‘huizhou‘
));
28 dump(Redis::smembers(‘xiaoshou‘
));
29 #获取并集
30 dump(Redis::sunion(‘huizhou‘,‘xiaoshou‘
));
31 #获取交集
32 dump(Redis::sinter("xiaoshou",‘huizhou‘
));
33 #获取huizhou与xiaoshou的差集
34 dump(Redis::sdiff("xiaoshou",‘huizhou‘
));
35 #获取xiaoshou与huizhou的差集
36 dump(Redis::sdiff(‘huizhou‘,"xiaoshou"
));
37 echo "<br/><hr/>"
;
38
39
40 // redis的list链表的使用
41 #栈 -> 先进后出
42 Redis::lpush("list1",‘one‘
);
43 Redis::lpush("list1",‘two‘
);
44 Redis::lpush("list1",‘three‘
);
45 dump(Redis::lrange(‘list1‘,0,-1
));
46
47 #队列 ->先进先出
48 Redis::rpush(‘rlist‘,‘one‘
);
49 Redis::rpush(‘rlist‘,‘two‘
);
50 Redis::rpush(‘rlist‘,‘three‘
);
51 dump(Redis::lrange("rlist",0,-1
));
52 #弹出队列和栈的元素
53 Redis::lpop("list1"
);
54
55 // redis的有序集合
56 Redis::zadd("zlist",1,"小明"
);
57 Redis::zadd("zlist",3,"惠州"
);
58 Redis::zadd("zlist",2,"加藤杰"
);
59 dump(Redis::zrange("zlist",0,-1
));
60 dump(Redis::zrevrange("zlist",0,-1
));
61
62
63 }
效果
二.队列应用小例子
1 /**
2 * 队列
3 */
4 public function Sickers() {
5 $sickers = [
6 ‘01李四,到0006诊所就诊‘,
7 ‘02张三,到0009诊所就诊‘,
8 ‘03王五,到0008诊所就诊‘
9 ];
10
11 foreach ($sickers as $sicker){
12 // 把病人放到队列中
13 Redis::rpush(‘Queue‘,$sicker);
14 }
15 return "挂号成功....";
16 }
17
18 public function Doctor() {
19 $sicker = Redis::lpop("Queue");
20 if ($sicker){
21 return $sicker;
22 }else{
23 return "医生下班····";
24 }
25 }
laravel-- 在laravel操作redis数据库的数据类型(string、哈希、无序集合、list链表、有序集合)
标签:ring 成功 小龙女 应用 inter inf 安装 hello bsp