thinkphp5操作redis系列教程】列表类型之lRange,lGetRange

<?php
namespace app\admin\controller;

use think\cache\driver\Redis;
use think\Controller;
use \think\Db;

class Index extends Controller
{


    //获取redis
    public function getRedis()
    {

        $redis = new \Redis();
        $redis->connect('127.0.0.1',6379);
        $redis->auth('root'); //redis密码
        echo $redis->get('name');
        $arr= $redis->lRange('list-key',0,1);
        dump($arr);


$redis->rPush('k1','a');
        $redis->rPush('k1','b');
        $redis->rPush('k1','c');
 
        // lRange() lGetRnage() 获取指定索引值范围内的所有元素
        $res = $redis->lRange('k1',0,1);
        var_dump($res);//array(2) { [0]=> string(1) "a" [1]=> string(1) "b" }
        echo "<hr/>";
        $res1 = $redis->lRange('k1',0,-1);
        var_dump($res1);//array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }
        echo "<hr/>";
        $res2 = $redis->lGetRange('k1',0,-1);
        var_dump($res2); // array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }


    }

}

  thinkphp5操作redis系列教程】列表类型之lRange,lGetRange

 

thinkphp5操作redis系列教程】列表类型之lRange,lGetRange

 

上一篇:thinkphp5百度云上传


下一篇:nginx配置thinkphp5