PHP中Redis使用pipeline批量删除

    public function  test()
    {
        $redis = new Redis();
        $port        =   6379;
        $host        =   '127.0.0.1';
        $redis->connect($host, $port, 30);

        $redis->hMset('aa',[1,2,3,4,5,6,7,8,9,10]);
        $len = $redis->hlen('aa');

        // pipelinepi操作
        echo time();
        echo "<br>";
        $redis->pipeline();
        for ($i = 0; $i < $len; $i++) {
            $redis->hdel('aa',$i);
        }
        $redis->exec();
        echo time();
        echo "<br>";


        // 普通循环删除
        echo time();
        echo "<br>";
        $redis->hMset('aa',[1,2,3,4,5,6,7,8,9,10]);
        for ($i = 0; $i < $len; $i++) {
            $redis->hdel('aa',$i);
        }
        echo time();
        echo "<br>";

        var_dump($redis->hget('aa',0));die;
    }
发布了40 篇原创文章 · 获赞 14 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/qq_41912505/article/details/104781149