在线时长缓存
/**
* @desc 在线时长缓存
* @var string
* @access public
*/
const KEY_ONLINE_CACHE = 'hd:online:cache';
/**
* @desc 插入 hd_online_data表
* @access public
* @param array $data 数据
* @return boolean
*/
public function addCache(array $data)
{
if (empty($data))
{
return ;
}
$redis = $this->data['redis_main'];
$redis->hmset(self::KEY_ONLINE_CACHE, $data);
return true;
}
/**
* @desc 查询 hd_online_data表
* @access public
* @param void
* @return boolean
*/
public function getCache()
{
$redis = $this->data['redis_main'];
return $redis->hgetall(self::KEY_ONLINE_CACHE);
}
/**
* 定时脚本执行区
* @access public
* @param void
* @return void
*/
public function add()
{
$data = $this->getCache();
foreach ($data as $k => &$v)
{
$renum = $v['datetime'];
if ($v['roomid'] > 1002)
{
$v['num'] += 5;
}
}
$data && array_multisort($renum, SORT_DESC, SORT_NUMERIC, $data);
$res = array ('sign_id' => rand(23,555),'client' => 'PC',
'nickname' => rand(999,9999),'create_timeline' => date('Y-m-d H:i:s'),
'last_timeline' => date('Y-m-d H:i:s'),'roomid' => rand(1000,1005),'datetime' => time(),'num' => 1);
array_unshift($data, $res);
$this->addCache($data);
print_r($data);
}