public function beforeRun(TaskInterface $task) { $this->_key = sprintf(self::CACHE_KEY, $task->key()); $notExist = Redis::cacheRedis()->setNx($this->_key, $task->beginTime); Redis::cacheRedis()->setTimeout($this->_key, self::CHECK_MAX_TIME); if ($notExist == false) { $lastTime = Redis::cacheRedis()->get($this->_key); if ($currentTime - $lastTime < self::CHECK_MAX_TIME) { return TaskInterface::STATUS_SKIP_BY_DUPLICATE; } } return true; }
public function beforeRun(TaskInterface $task) { if (isset($this->_units[$this->unit]) == false) { $this->unit = self::UNIT_MINUTE; } $timeString = date($this->_units[$this->unit][0]) . $this->unit; $cacheKey = sprintf(self::CACHE_KEY, $task->key(), $timeString); $currentCount = Redis::cacheRedis()->incrBy($cacheKey, 1); if ($currentCount == 1) { $timeout = $this->_units[$this->unit][1]; Redis::cacheRedis()->setTimeout($cacheKey, $timeout); } if ($currentCount > $this->max) { return TaskInterface::STATUS_SKIP_BY_LIMIT; } return true; }
/** * 获取请求校验码 * @param TaskInterface $task [description] * @return [type] [description] */ public static function getTarthHeader(TaskInterface $task) { $crypted = ""; openssl_public_encrypt(microtime(true) . $task->key(), $crypted, self::OPENSSL_PUBLIC_KEY); return $crypted; }