ManaPHP\Meter\Round::record PHP Метод

record() публичный Метод

public record ( string $type, string $id, integer $duration ) : static
$type string
$id string
$duration integer
Результат static
    public function record($type, $id, $duration)
    {
        $begin_time = (int) (time() / $duration) * $duration;
        if ($this->_useRedis) {
            $this->redis->hIncrBy($this->_prefix . $type . ':' . $begin_time . '-' . $duration, $id, 1);
        } else {
            /**
             * @var \ManaPHP\Meter\Round\Model $model
             * @var \ManaPHP\Meter\Round\Model $instance
             */
            $model = new $this->_model();
            $hash = md5($type . ':' . $begin_time . '-' . $duration . ':' . $id);
            $r = $model::updateAll(['count = count + 1'], ['hash' => $hash]);
            if ($r === 0) {
                $instance = new $this->_model();
                $instance->hash = $hash;
                $instance->type = $type;
                $instance->id = $id;
                $instance->count = 1;
                $instance->begin_time = $begin_time;
                $instance->duration = $duration;
                $instance->created_time = time();
                try {
                    $instance->create();
                } catch (\Exception $e) {
                    $model::updateAll(['count = count + 1'], ['hash' => $hash]);
                }
            }
        }
        return $this;
    }