/** * @inheritdoc */ public function registerNonceAndTimestamp($nonce, $timestamp, ConsumerInterface $consumer) { if ($this->checkNonceAndTimestampUnicity($nonce, $timestamp, $consumer)) { $noncesRedisKey = $this->noncesRedisKey($consumer, $timestamp); $this->client->sadd($noncesRedisKey, [$nonce]); $this->client->expire($noncesRedisKey, $this->ttl); $timestampsKey = $this->timestampsKey($consumer); $this->client->zadd($timestampsKey, $timestamp, $timestamp); // While we're here, only keep the top 10 items. $sortedSet = $this->client->zrevrange($timestampsKey, 0, -1); if (is_array($sortedSet) && !empty($sortedSet)) { $lastTimestamp = $sortedSet[0]; $this->client->zremrangebyscore($timestampsKey, 0, $lastTimestamp - 1); } return true; } else { return false; } }
/** * @test */ public function it_throws_an_error_when_using_a_timestamp_smaller_than_last_registered() { $this->client->zadd("timestamps/key:{$this->consumer->getConsumerKey()}", 500, 500); $this->setExpectedException('InvalidArgumentException', 'Timestamp must be bigger than your last timestamp we have recorded'); $this->nonceProvider->checkNonceAndTimestampUnicity('foo', 499, $this->consumer); }