Laravel 操作redis的各种数据类型
安装redis和连接redis数据库
在controller头部引入
public function RedisdDbOne() { // 清空Redis数据库 Redis::flushall(); // redis的string类型 Redis::set("laravel","Hello woshi laravel"); dump(Redis::get("laravel")) ; // redis的哈希类型 Redis::hmset('happy:huizhou',['name'=>"惠州"]); Redis::hmset("fail:xiaoshou",[ "lover" => "黑嘿嘿?", 'nice' => "我是xiaoshou", '挑衅' => '来打我啊' ]); dump(Redis::hgetall("happy:huizhou")); dump(Redis::hgetall('fail:xiaoshou')); echo "<br/><hr/>"; // redis的无序列表 Redis::sAdd('huizhou',['小东','小追命','小龙女']); Redis::sAdd('xiaoshou',['小明','小追命','阳光宅猫']); #获取无序集合 dump(Redis::smembers('huizhou')); dump(Redis::smembers('xiaoshou')); #获取并集 dump(Redis::sunion('huizhou','xiaoshou')); #获取交集 dump(Redis::sinter("xiaoshou",'huizhou')); #获取huizhou与xiaoshou的差集 dump(Redis::sdiff("xiaoshou",'huizhou')); #获取xiaoshou与huizhou的差集 dump(Redis::sdiff('huizhou',"xiaoshou")); echo "<br/><hr/>"; // redis的list链表的使用 #栈 -> 先进后出 Redis::lpush("list1",'one'); Redis::lpush("list1",'two'); Redis::lpush("list1",'three'); dump(Redis::lrange('list1',0,-1)); #队列 ->先进先出 Redis::rpush('rlist','one'); Redis::rpush('rlist','two'); Redis::rpush('rlist','three'); dump(Redis::lrange("rlist",0,-1)); #弹出队列和栈的元素 Redis::lpop("list1"); // redis的有序集合 Redis::zadd("zlist",1,"小明"); Redis::zadd("zlist",3,"惠州"); Redis::zadd("zlist",2,"加藤杰"); dump(Redis::zrange("zlist",0,-1)); dump(Redis::zrevrange("zlist",0,-1)); }