webman-php / redis-queue

Message queue system written in PHP for webman.
https://www.workerman.net/webman
25 stars 9 forks source link

延迟队列,为啥一次性只拉取128个 #2

Closed shuyabin closed 2 years ago

shuyabin commented 2 years ago

我这边在拉取延迟队列的时候发现消费的比较慢,看了一下源码一次性只拉取了128个,想咨询一下大佬这样设计的想法是啥?

    $retry_timer = Timer::add(1, function () {
            $now = time();
            $options = ['LIMIT', 0, 128];
            $this->_redisSend->zrevrangebyscore(static::QUEUE_DELAYED, $now, '-inf', $options, function($items){
                if ($items === false) {
                    throw new RuntimeException($this->_redisSend->error());
                }
                foreach ($items as $package_str) {
                    $this->_redisSend->zRem(static::QUEUE_DELAYED, $package_str, function ($result) use ($package_str) {
                        if ($result !== 1) {
                            return;
                        }
                        $package = \json_decode($package_str, true);
                        if (!$package) {
                            $this->_redisSend->lPush(static::QUEUE_FAILD , $package_str);
                            return;
                        }
                        $this->_redisSend->lPush(static::QUEUE_WAITING . $package['queue'], $package_str);
                    });
                }
            });
        });