/** * @param PriorityItem[] $items * @return int the number of elements added * The ids of items will be set on return */ public function enqueue(array $items) { $n = count($items); $uniqueId = $this->autoIncrementingId->getUniqueId($n); foreach ($items as $item) { $item->id = $uniqueId - $n + 1; $n--; } $keyValues = []; $keyScores = []; foreach ($items as $item) { $keyValues[$item->id] = serialize($item->value); $keyScores[$item->id] = $item->score; } $this->hashTable->set($keyValues); return $this->redis->zadd($this->name, $keyScores); }
public function test_unique_id() { $this->assertEquals(1, $this->uniqueId->getUniqueId()); $this->assertEquals(11, $this->uniqueId->getUniqueId(10)); }