public function record($type, $id)
{
if ($this->_useRedis) {
$this->redis->hIncrBy($this->_prefix . $type, $id, 1);
} else {
/**
* @var \ManaPHP\Meter\Linear\Model $model
* @var \ManaPHP\Meter\Linear\Model $instance
*/
$model = new $this->_model();
$hash = md5($type . ':' . $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->created_time = time();
try {
$instance->create();
} catch (\Exception $e) {
$model::updateAll(['count =count + 1'], ['hash' => $hash]);
}
}
}
return $this;
}