Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="fromScore"></param>
        /// <param name="toScore">-1: all</param>
        /// <returns></returns>
        public bool RemoveRankByScore <V>(string key, double fromScore, double?toScore) where V : RankEntity, new()
        {
            LoadingStatus loadStatus;
            CacheList <V> cacheItems;

            if (!TryGetCacheItem(key, true, out cacheItems, out loadStatus))
            {
                return(false);
            }
            List <V> removeList;

            if (!cacheItems.RemoveAll(t => t.Score >= fromScore && (!toScore.HasValue || t.Score <= toScore.Value), out removeList))
            {
                return(true);
            }
            foreach (var entity in removeList)
            {
                entity.IsInCache = false;
                entity.IsExpired = true;
                entity.OnDelete();
            }
            var            schema    = EntitySchemaSet.Get <V>();
            TransSendParam sendParam = new TransSendParam(key)
            {
                Schema = schema
            };

            return(_cachePool.TrySetRankData(sendParam, removeList.ToArray()));
        }
Пример #2
0
 /// <summary>
 /// 尝试发送数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dataList"></param>
 /// <param name="sendParam"></param>
 public void SendData <T>(T[] dataList, TransSendParam sendParam) where T : AbstractEntity, new()
 {
     //todo modify use redis
     CacheChangeManager.Current.SetEntity(dataList);
     //if (!sendParam.OnlyRedis)
     //{
     //    _dbTransponder.SendData(dataList, sendParam);
     //}
     //_redisTransponder.SendData(dataList, sendParam);
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isChange">更新到库中是全部数据还是改变的数据</param>
        /// <param name="changeKey"></param>
        protected bool UpdateGroup(bool isChange = true, string changeKey = null)
        {
            var            changeList = DataContainer.GetChangeGroup(changeKey, isChange);
            TransSendParam sendParam  = new TransSendParam()
            {
                IsChange = isChange
            };

            return(DoSend(changeList, sendParam));
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isChange">更新到库中是全部数据还是改变的数据</param>
        /// <param name="changeKey"></param>
        protected void UpdateQueue(bool isChange = true, string changeKey = null)
        {
            var            changeList = DataContainer.GetChangeQueue(changeKey, isChange);
            TransSendParam sendParam  = new TransSendParam()
            {
                IsChange = isChange
            };

            DoSend(changeList, sendParam);
        }
Пример #5
0
 /// <summary>
 /// 尝试发送数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dataList"></param>
 /// <param name="sendParam"></param>
 public void SendData <T>(T[] dataList, TransSendParam sendParam) where T : AbstractEntity, new()
 {
     //modify reason:提交到Redis同步队列处理
     DataSyncQueueManager.Send(dataList);
     //if (!sendParam.OnlyRedis)
     //{
     //    _dbTransponder.SendData(dataList, sendParam);
     //}
     //_redisTransponder.SendData(dataList, sendParam);
 }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="groupList"></param>
 /// <param name="sendParam"></param>
 protected void DoSend(GroupList <string, T> groupList, TransSendParam sendParam)
 {
     foreach (var groupKey in groupList.Keys)
     {
         List <T> list;
         groupList.TryGetValue(groupKey, out list);
         sendParam.RedisKey = groupKey;
         DataContainer.SendData(list.ToArray(), sendParam);
         DataContainer.UnChangeNotify(groupKey);
     }
 }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="sendParam"></param>
        protected void DoSend(IEnumerable <KeyValuePair <string, T> > dataList, TransSendParam sendParam)
        {
            var keyValuePairs = dataList as KeyValuePair <string, T>[] ?? dataList.ToArray();

            DataContainer.SendData(keyValuePairs.Select(pair => pair.Value).ToArray(), sendParam);
            var groupList = keyValuePairs.GroupBy(t => t.Key);

            foreach (var g in groupList)
            {
                DataContainer.UnChangeNotify(g.Key);
            }
        }
Пример #8
0
        /// <summary>
        /// 删除数据并移出缓存
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Delete(T value)
        {
            string key = value.GetKeyCode();

            return(TryRemove(key, item =>
            {
                value.OnDelete();
                TransSendParam sendParam = new TransSendParam()
                {
                    IsChange = true
                };
                DoSend(new[] { new KeyValuePair <string, T>(key, value) }, sendParam);
                return true;
            }));
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataList"></param>
        /// <param name="sendParam"></param>
        protected bool DoSend(IEnumerable <KeyValuePair <string, T> > dataList, TransSendParam sendParam)
        {
            var keyValuePairs = dataList as KeyValuePair <string, T>[] ?? dataList.ToArray();

            if (DataContainer.SendSync(keyValuePairs.Select(pair => pair.Value)))
            {
                var groupList = keyValuePairs.GroupBy(t => t.Key);
                foreach (var g in groupList)
                {
                    DataContainer.UnChangeNotify(g.Key);
                }
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 删除数据并移出缓存
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Delete(T value)
        {
            string key        = value.GetKeyCode();
            string personalId = value.PersonalId;

            return(TryRemove(personalId, key, entity =>
            {
                entity.OnDelete();
                TransSendParam sendParam = new TransSendParam()
                {
                    IsChange = true
                };
                return DoSend(new[] { new KeyValuePair <string, T>(personalId, value) }, sendParam);
            }));
        }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isChange">更新到库中是全部数据还是改变的数据</param>
        /// <param name="changeKey"></param>
        protected void UpdateQueue(bool isChange = true, string changeKey = null)
        {
            var changeList = DataContainer.GetChangeQueue(changeKey, isChange);
            var groupList  = new GroupList <string, T>();

            foreach (var pair in changeList)
            {
                groupList.TryAdd(pair.Value.PersonalId, pair.Value);
            }
            TransSendParam sendParam = new TransSendParam()
            {
                IsChange = isChange
            };

            DoSend(groupList, sendParam);
        }
Пример #12
0
        /// <summary>
        /// 删除数据并移出缓存
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Delete(T value)
        {
            string key = value.GetKeyCode();

            return(TryRemove(key, item =>
            {
                value.OnDelete();
                var groupList = new GroupList <string, T>();
                groupList.TryAdd(key, value);
                TransSendParam sendParam = new TransSendParam()
                {
                    IsChange = true
                };
                DoSend(groupList, sendParam);
                return true;
            }));
        }
Пример #13
0
        /// <summary>
        /// 删除数据并移出缓存
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Delete(T value)
        {
            string key        = value.GetKeyCode();
            string personalId = value.PersonalId;

            return(TryRemove(personalId, key, entity =>
            {
                entity.OnDelete();
                var groupList = new GroupList <string, T>();
                groupList.TryAdd(personalId, entity);
                TransSendParam sendParam = new TransSendParam()
                {
                    IsChange = true
                };
                DoSend(groupList, sendParam);
                return true;
            }));
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="dataList"></param>
        public bool SetRangeRank <V>(string key, params V[] dataList) where V : RankEntity, new()
        {
            LoadingStatus loadStatus;
            CacheList <V> cacheItems;

            if (!TryGetCacheItem(key, true, out cacheItems, out loadStatus))
            {
                return(false);
            }
            var            schema    = EntitySchemaSet.Get <V>();
            TransSendParam sendParam = new TransSendParam(key)
            {
                Schema = schema
            };

            foreach (var item in dataList)
            {
                item.IsInCache = true;
                cacheItems.InsertSort(item, (x, y) => x.CompareTo(y));
            }
            return(_cachePool.TrySetRankData(sendParam, dataList));
        }
Пример #15
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="V"></typeparam>
 /// <param name="dataList"></param>
 /// <param name="sendParam"></param>
 public void SendData <V>(V[] dataList, TransSendParam sendParam) where V : AbstractEntity, new()
 {
     _cachePool.SendData(dataList, sendParam);
 }
Пример #16
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="sendParam"></param>
 /// <param name="dataList"></param>
 /// <returns></returns>
 public bool TrySetRankData <T>(TransSendParam sendParam, params T[] dataList) where T : RankEntity, new()
 {
     return(_redisTransponder.SendData(dataList, sendParam));
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="groupList"></param>
 /// <param name="sendParam"></param>
 protected void DoTimeSend(GroupList <string, T> groupList, TransSendParam sendParam)
 {
 }
Пример #18
0
 public RedisDataSender(TransSendParam sendParam)
 {
     _sendParam = sendParam;
 }