public bool AccessStatistics(string id, string classify) { var type = VideoCommonService.GetVideoType(classify) ?? ""; //日排行 _redisService.SortedSetIncrement(GetDayRankingKeyByType(type), id, 1, 60 * 24 * 15);//15天 //总排行 _redisService.SortedSetIncrement(VideoCommonService.TotalRankingKey, id, 1); return(true); }
private List <Video> GetUpdateList(string type) { int count = type == "伦理" ? 6 : 12; var listKey = $"VideoIndexUpdateList_{type}"; if (!_memoryCache.TryGetValue(listKey, out List <Video> result)) { result = new List <Video>(); result = _videoService.GetVideoByClassify(VideoCommonService.GetVideoClassify(type), 1, count); if (result != null && result.Count > 0) { _memoryCache.Set(listKey, result, new DateTimeOffset(DateTime.Now.AddMinutes(20))); } } return(result); }
public IActionResult VideoList(string classify, string index) { if (string.IsNullOrEmpty(classify)) { return(Redirect("/video")); } var name = VideoCommonService.GetVideoRealClassify(classify, out string type); if (name == null) { return(Redirect("/video")); } int.TryParse(index, out int currentIndex); currentIndex = currentIndex < 1 ? 1 : currentIndex; var pageSize = 18; var listKey = $"VideoList_{name}_{currentIndex}"; if (!_memoryCache.TryGetValue(listKey, out VideoSearchResult result)) { long totalCount = 0; result = new VideoSearchResult() { PageIndex = currentIndex, PageSize = pageSize }; var list = _videoService.GetVideoByClassify(name, currentIndex, pageSize, out totalCount); result.Result = list; result.TotalCount = totalCount; result.Key = name; if (list != null && list.Count > 0) { _memoryCache.Set(listKey, result, new DateTimeOffset(DateTime.Now.AddMinutes(20))); } } ViewData["VideoType"] = type; ViewData["VideoList"] = result; return(View()); }
public IActionResult VideoDetail(string id) { //详情 long vid = 0; if (!long.TryParse(id, out vid)) { return(Redirect("/error")); } var videoDetailKey = $"VideoDetail_{id}"; var videoDetail = _redisService.Get <VideoDetail>(videoDetailKey); if (videoDetail == null) { var video = _videoService.GetVideo(vid); if (video == null) { return(Redirect("/error")); } var videoSource = _videoService.GetVideoSourceByVideo(video.Id); if (videoSource == null) { return(Redirect("/error")); } videoDetail = new VideoDetail() { Video = video, VideoSource = videoSource }; var cacheTime = 60;//1小时 var type = VideoCommonService.GetVideoType(video.Classify); if (type == "电影" || type == "伦理") { cacheTime = 60 * 24 * 3;//3天 } _redisService.Set(videoDetailKey, videoDetail, cacheTime); } var videoType = VideoCommonService.GetVideoType(videoDetail.Video.Classify);; //热播 var hotListKey = "VideoHotList_" + videoType; if (!_memoryCache.TryGetValue(hotListKey, out List <VideoRank> hotList)) { hotList = new List <VideoRank>(); var dayRanking = _videoRankingService.GetDayRankingByType(videoType, 1, 10);//日榜前10 var dayRankingList = _videoService.GetVideoList(dayRanking.Select(x => Convert.ToInt64(x.Key))); dayRanking.ForEach(item => { var dayRankingItem = dayRankingList.FirstOrDefault(x => x.Id == Convert.ToInt64(item.Key)); if (dayRankingItem != null) { hotList.Add(ConvertVideoToVideoRank(dayRankingItem, item.Value)); } }); _memoryCache.Set(hotListKey, hotList, new DateTimeOffset(DateTime.Now.AddMinutes(5)));//5分钟 } ViewData["VideoDetail_HotList"] = hotList; //推荐 var recommendKey = "VideoRecommendList_" + videoType; if (!_memoryCache.TryGetValue(recommendKey, out List <VideoRank> recommendList)) { recommendList = new List <VideoRank>(); var weekRanking = _videoRankingService.GetWeekRankingByType(videoType, 1, 4);//周榜前4 var weekRankingList = _videoService.GetVideoList(weekRanking.Select(x => Convert.ToInt64(x.Key))); weekRanking.ForEach(item => { var weekRankingItem = weekRankingList.FirstOrDefault(x => x.Id == Convert.ToInt64(item.Key)); if (weekRankingItem != null) { recommendList.Add(ConvertVideoToVideoRank(weekRankingItem, item.Value)); } }); _memoryCache.Set(recommendKey, recommendList, new DateTimeOffset(DateTime.Now.AddHours(1)));//1小时 } ViewData["VideoDetail_RecommendList"] = recommendList; //统计 _videoRankingService.AccessStatistics(id, videoDetail.Video.Classify); ViewData["VideoDetail_VideoType"] = videoType; return(View(videoDetail)); }
/// <summary> /// 日排行key /// </summary> private string GetDayRankingKeyByType(string type, DateTime?date = null) { return($"{VideoCommonService.DayRankingKey}{(date.HasValue ? date.Value.ToString("yyyyMMdd") : DateTime.Today.ToString("yyyyMMdd"))}{type}"); }