SET notify-keyspace-events Ex
SUBSRCIBE __keyevent@0__:expired
$redisSub = new Redis() or die("Can't create to redis database instance!\n");
$redisSub->connect('localhost', 6379) or die("Can't connect to redis database!\n");
$redisSub->select(2) or die("Can't select database!\n");
$redisSub->setOption(Redis::OPT_READ_TIMEOUT, -1);
$redisSub->config('SET', 'notify-keyspace-events', 'Ex');
$redisSub->subscribe(['__keyevent@2__:expired'], 'msg'); // db 2
function msg($redisSub, $chan, $msg) {
}
function bytesFormat ($size) {
$postfix = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; // xD
$i = 0;
while ($size >= 1000) {
$i++;
$size = $size / 1000;
if ($i == count($postfix) - 1) {
break;
}
}
$size = round($size * 100) / 100;
return $size . ' ' . $postfix[$i];
}
echo bytesFormat(300).PHP_EOL;
echo bytesFormat(330816).PHP_EOL;
echo bytesFormat(1433860).PHP_EOL;
300 B
330.82 KB
1.43 MB