/** * @see QueueInterface::pop() */ public function pop() { $command = array('findandmodify' => $this->collection->getName(), 'remove' => 1, 'fields' => array('task' => 1), 'query' => array('eta' => array('$lte' => new \MongoDate())), 'sort' => array('eta' => 1)); $result = $this->collection->db->command($command); if (!$result['ok']) { throw new \RuntimeException($result['errmsg']); } $data = $result['value']; return $data ? $this->serializer->unserialize($data['task']) : false; }
/** * @see QueueInterface::pop() */ public function pop() { $sql = 'SELECT task FROM ' . $this->tableName . ' WHERE eta <= :now ORDER BY eta, id LIMIT 1'; $stmt = $this->prepareStatement($sql); $stmt->bindValue(':now', date(static::DATETIME_FORMAT)); if (!$stmt->execute()) { $err = $stmt->errorInfo(); throw new \RuntimeException($err[2]); } $data = $stmt->fetchColumn(); return $data ? $this->serializer->unserialize($data) : false; }
/** * @see QueueInterface::pop() */ public function pop() { while (true) { if ($this->tryLock()) { $range = $this->redis->zRangeByScore('tasks', '-inf', time(), array('limit' => array(0, 1))); if (empty($range)) { $this->releaseLock(); return false; } $key = reset($range); $this->redis->zRem('tasks', $key); $this->releaseLock(); $data = substr($key, strpos($key, '@') + 1); return $this->serializer->unserialize($data); } // the lock failed to be released by the client $this->releaseLock(); } }