private void ProcessEKZanerAndReader() { var redis = new RedisManager2<WeChatRedisConfig>(); // using (UserRepository r = new UserRepository()) { foreach (var v in r.GetAllEKToday()) { long id = v.ID; #region zan using (UserRepository rzan = new UserRepository()) { var listDBZaner = rzan.GetEKZaners(id); var listRedisZaner = redis.GetRangeByRank<EKTodayRedis, EKZanPepleZsetAttribute>(id.ToString()); if (listDBZaner == null) listDBZaner = new List<article_praise>(); if (listRedisZaner == null) listRedisZaner = new KeyValuePair<string, double>[] { }; //LogHelper.LogInfoAsync(typeof(Service1), "zan:" + id.ToString() +" " +listDBZaner.Count()+" " +listRedisZaner.Count()); //DB -> reids if (listDBZaner.Count() > 0 || listRedisZaner.Count() > 0) { if (listDBZaner.Count() > listRedisZaner.Count()) { foreach (var p in listDBZaner) { DateTime t = p.praisetime != null ? p.praisetime.Value : DateTime.Now; double score = BK.CommonLib.Util.CommonHelper.ToUnixTime(t); redis.SetScoreEveryKey<EKTodayRedis, EKZanPepleZsetAttribute>(id.ToString(), p.useraccount_uuid.ToString(), score); //LogHelper.LogInfoAsync(typeof(Service1), "zan:" + id.ToString()+" uuid:"+p.useraccount_uuid.ToString()+" score:"+score.ToString()); } } else { foreach (var p in listRedisZaner) { Guid uuid = Guid.Parse(p.Key); double score = p.Value; rzan.AddEKZaner(id, uuid, score); //LogHelper.LogInfoAsync(typeof(Service1), "-->zan:" + id.ToString() + " uuid:" + p.Key + " score:" + score.ToString()); } } } } #endregion #region reader using (UserRepository rreader = new UserRepository()) { var listDBreader = rreader.GetEKReaders(id); var listRedisreader = redis.GetRangeByRank<EKTodayRedis, EKReadPepleZsetAttribute>(id.ToString()); if (listDBreader == null) listDBreader = new List<article_reader>(); if (listRedisreader == null) listRedisreader = new KeyValuePair<string, double>[] { }; //DB -> reids if (listDBreader.Count() > 0 || listRedisreader.Count() > 0) { if (listDBreader.Count() > listRedisreader.Count()) { foreach (var p in listDBreader) { DateTime t = p.readtime != null ? p.readtime.Value : DateTime.Now; double score = BK.CommonLib.Util.CommonHelper.ToUnixTime(t); redis.SetScoreEveryKey<EKTodayRedis, EKReadPepleZsetAttribute>(id.ToString(), p.useraccount_uuid.ToString(), score); } } else { foreach (var p in listRedisreader) { Guid uuid = Guid.Parse(p.Key); double score = p.Value; rreader.AddEKReader(id, uuid, score); } } } } #endregion } } }
private void ProcessEK() { var redis = new RedisManager2<WeChatRedisConfig>(); //同步articl 数据 using (UserRepository r = new UserRepository()) { Dictionary<long, int> updateReadDic = new Dictionary<long, int>(); Dictionary<long, int> updateZanDic = new Dictionary<long, int>(); foreach(var v in r.GetAllEKToday().Where(ekt => ekt.IsPublic == true)) { var index = EKArticleManager.CopyFromDB(v); EKArticleManager.AddOrUpdate(index); //更新read count double readScore = redis.GetScore<EKTodayRedis, EKReadCountZsetAttribute>(v.ID.ToString()); int rrCount = Convert.ToInt32(readScore); if(rrCount < v.ReadPoint) { EKArticleManager.SetReadCount(v.ID, v.ReadPoint.Value); } else { //r.SetReadCount_TB(v.ID, rrCount); updateReadDic.Add(v.ID, rrCount); } //更新zanshu double zanscore = redis.GetScore<EKTodayRedis, EKZanCountZsetAttribute>(v.ID.ToString()); int zrCount = Convert.ToInt32(zanscore); if(zrCount < v.HitPoint) { EKArticleManager.SetZan(v.ID, v.HitPoint.Value); } else { //r.SetZanCount(v.ID, zrCount); updateZanDic.Add(v.ID, zrCount); } } //update read foreach(var pair in updateReadDic) { r.SetReadCount_TB(pair.Key, pair.Value); } //update zan foreach(var pair in updateZanDic) { r.SetZanCount(pair.Key, pair.Value); } } }