video_live_recommend.auto_cache.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class video_live_recommend_auto_cache extends auto_cache
  3. {
  4. private $key = "video:live:index";
  5. public function load($hot_list)
  6. {
  7. $key_bf = $this->key . '_bf';
  8. $live_video = $GLOBALS['cache']->get($this->key, true);
  9. if ($live_video === false) {
  10. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  11. if (!$is_ok) {
  12. return $GLOBALS['cache']->get($key_bf, true);
  13. }
  14. $live_video = array();
  15. if (count($hot_list) > 6) {
  16. foreach (array_rand($hot_list, 6) as $key) {
  17. $live_video[] = $hot_list[$key];
  18. }
  19. } else {
  20. $live_video = $hot_list;
  21. }
  22. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  23. $video_redis = new VideoRedisService();
  24. foreach ($live_video as $key => $value) {
  25. $room = $video_redis->getRow_db($value['room_id'], array('channelid', 'begin_time', 'create_time'));
  26. $live_video[$key]['channelid'] = $room['channelid'];
  27. if ($value['live_in'] == 3) {
  28. $file_info = load_auto_cache('video_file', array(
  29. 'id' => $value['room_id'],
  30. 'video_type' => $value['video_type'],
  31. 'channelid' => $room['channelid'],
  32. 'begin_time' => $room['begin_time'],
  33. 'create_time' => $room['create_time'],
  34. ));
  35. $live_video[$key]['fileid'] = $file_info['file_id'];
  36. $live_video[$key]['play_url'] = $file_info['play_url'];
  37. }
  38. }
  39. if (!empty($live_video)) {
  40. $GLOBALS['cache']->set($this->key, $live_video, 60, true);
  41. $GLOBALS['cache']->set($key_bf, $live_video, 86400, true);//备份
  42. }
  43. }
  44. return $live_video;
  45. }
  46. public function rm()
  47. {
  48. $GLOBALS['cache']->clear_by_name($this->key);
  49. }
  50. public function clear_all()
  51. {
  52. $GLOBALS['cache']->clear_by_name($this->key);
  53. }
  54. }