public function increment($key, $by_value = 1, $limit_keys_count = 0, $ttl = 259200)
{
if (empty($key)) {
$this->ReportError('empty keys are not allowed', __LINE__);
return false;
}
if (is_numeric($by_value) && !$this->redis->Exists($this->serialize_key_prefix . $key)) {
if (!($key_exists = $this->redis->Exists($this->prefix . $key)) || is_numeric($this->redis->Get($this->prefix . $key))) {
if ($by_value >= 0) {
$result = $this->redis->IncrBy($this->prefix . $key, $by_value);
} else {
$result = $this->redis->DecrBy($this->prefix . $key, $by_value * -1);
}
if ($result !== false) {
if ($ttl > 0) {
$this->redis->Expire($this->prefix . $key, $ttl);
}
return $result;
}
}
}
if (!$this->acquire_key($key, $auto_unlocker)) {
return false;
}
$value = $this->read($key);
if ($value === null || $value === false) {
return $this->save($key, $by_value, $ttl);
}
if (is_array($value)) {
$value = $this->incrementArray($limit_keys_count, $value, $by_value);
} elseif (is_numeric($value) && is_numeric($by_value)) {
$value += $by_value;
} else {
$value .= $by_value;
}
if ($this->save($key, $value, $ttl)) {
return $value;
} else {
return false;
}
}