+ [refac] add method to get memory usage.
This commit is contained in:
Vendored
+12
@@ -889,4 +889,16 @@ class cache
|
||||
{
|
||||
$this->cache->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用情况。
|
||||
* Get memory usage.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function memory(string $type)
|
||||
{
|
||||
return $this->cache->memory($type);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+18
@@ -81,4 +81,22 @@ class ApcuDriver implements CacheInterface
|
||||
{
|
||||
return (bool) apcu_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用情况。
|
||||
* Get memory usage.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function memory($type)
|
||||
{
|
||||
$info = apcu_sma_info(true);
|
||||
|
||||
if($type == 'total') return \helper::formatKB($info['seg_size']);
|
||||
if($type == 'free') return \helper::formatKB($info['avail_mem']);
|
||||
if($type == 'used') return \helper::formatKB($info['seg_size'] - $info['avail_mem']);
|
||||
if($type == 'rate') return round(($info['seg_size'] - $info['avail_mem']) / $info['seg_size'] * 100, 2);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+18
@@ -230,4 +230,22 @@ class RedisDriver implements CacheInterface
|
||||
{
|
||||
return (bool) $this->redis->exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用情况。
|
||||
* Get memory usage.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public function memory($type)
|
||||
{
|
||||
$info = $this->redis->info();
|
||||
|
||||
if($type == 'total') return $info['total_system_memory_human'];
|
||||
if($type == 'free') return \helper::formatKB($info['total_system_memory'] - $info['used_memory']);
|
||||
if($type == 'used') return $info['used_memory_human'];
|
||||
if($type == 'rate') return round(($info['used_memory'] / $info['total_system_memory']) * 100, 2);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user