码迷,mamicode.com
首页 > 其他好文 > 详细

在线时长缓存

时间:2015-12-25 19:08:31      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

    
    /**
     * @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);
      }

在线时长缓存

标签:

原文地址:http://www.cnblogs.com/sixiong/p/5076548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!