public function flush($type, $id = null)
{
if ($this->_useRedis) {
$it = null;
while ($keys = $this->redis->scan($it, $this->_prefix . $type . ':*', 32)) {
/** @noinspection ForeachSourceInspection */
foreach ($keys as $key) {
$parts = explode('-', substr($key, strrpos($key, ':') + 1));
$begin_time = $parts[0];
$duration = $parts[1];
if ($id !== null) {
$count = $this->redis->hGet($key, $id);
if ($count !== '') {
$this->_save($type, $id, $begin_time, $duration, $count);
}
if (time() - $begin_time > $duration) {
$this->redis->hDel($key, $id);
}
} else {
$it2 = null;
while ($hashes = $this->redis->hScan($key, $it2, '', 32)) {
foreach ($hashes as $hash => $count) {
$this->_save($type, $hash, $begin_time, $duration, $count);
}
}
if (time() - $begin_time > $duration) {
$this->redis->delete($key);
}
}
}
}
}
}