/// <summary> /// 加载Enity数据 /// </summary> /// <param name="receiveParam"></param> /// <param name="periodTime"></param> /// <param name="isReplace"></param> /// <returns></returns> protected bool TryLoadCache(TransReceiveParam receiveParam, int periodTime, bool isReplace) { //todo: trace TryLoadCache var watch = RunTimeWatch.StartNew(string.Format("Try load cache data:{0}", receiveParam.Schema.EntityType.FullName)); try { List <T> dataList; if (DataContainer.TryReceiveData(receiveParam, out dataList)) { watch.Check("received count:" + dataList.Count, 20); if (dataList.Count == 0) { return(true); } return(InitCache(dataList, periodTime, isReplace)); } } catch (Exception ex) { string name = receiveParam.Schema != null ? receiveParam.Schema.EntityName : typeof(T).FullName; TraceLog.WriteError("Try load cache \"{0}\" data error:{1}", name, ex); } finally { watch.Flush(false, 500); } return(false); }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <param name="receiveParam"></param> /// <returns></returns> public List <V> LoadFrom <V>(TransReceiveParam receiveParam) where V : AbstractEntity, new() { List <V> dataList = null; if (_container != null && _loadFactory != null) { if (_container.IsEmpty) { Initialize(); } if (_container.LoadingStatus != LoadingStatus.None) { //新增的数据不能清除掉 _container.Collection.Clear(); _container.ResetStatus(); } _container.OnLoadFactory((r) => { if (_cachePool.TryReceiveData(receiveParam, out dataList)) { return(true); } return(false); }, true); } return(dataList); }
/// <summary> /// 尝试接收数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns>return null is load error</returns> public bool TryReceiveData <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { bool result = false; dataList = null; //表为空时,不加载数据 if (receiveParam.Schema == null || string.IsNullOrEmpty(receiveParam.Schema.Name) || DbConnectionProvider.CreateDbProvider(receiveParam.Schema) == null) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } //配置库不放到Redis,尝试从DB加载 if (receiveParam.Schema.AccessLevel == AccessLevel.ReadOnly) { return(_dbTransponder.TryReceiveData(receiveParam, out dataList)); } if (!string.IsNullOrEmpty(receiveParam.RedisKey) && _redisTransponder.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count > 0) { return(true); } //从Redis历史记录表中加载 result = TryLoadHistory(receiveParam.RedisKey, out dataList); } return(result); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="receiveParam"></param> /// <param name="periodTime"></param> /// <param name="isReplace"></param> /// <returns></returns> protected bool TryLoadRankCache(string key, TransReceiveParam receiveParam, int periodTime, bool isReplace) { //todo: trace var watch = RunTimeWatch.StartNew(string.Format("Try load rank cache:{0}-{1}", receiveParam.Schema.EntityType.FullName, key)); try { List <T> dataList; if (DataContainer.TryReceiveData(receiveParam, out dataList)) { CacheItemSet itemSet; DataContainer.TryGetOrAddRank(key, out itemSet, periodTime); watch.Check("received count:" + dataList.Count); InitCache(dataList, periodTime, isReplace); watch.Check("Init cache:"); itemSet.OnLoadSuccess(); return(true); } } finally { watch.Flush(true, 20); } TraceLog.WriteError("Try load cache data:{0} error.", typeof(T).FullName); return(false); }
/// <summary> /// 处理加载数据参数 /// </summary> /// <param name="personalId"></param> /// <param name="isReplace"></param> /// <returns></returns> protected bool ProcessLoadParam(string personalId, bool isReplace) { string redisKey = CreateRedisKey(personalId); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); string paramName = receiveParam.Schema.PersonalName; int periodTime = receiveParam.Schema.PeriodTime; int maxCount = receiveParam.Schema.Capacity; var provider = DbConnectionProvider.CreateDbProvider(receiveParam.Schema); if (receiveParam.Schema.StorageType.HasFlag(StorageType.ReadOnlyDB) || receiveParam.Schema.StorageType.HasFlag(StorageType.ReadWriteDB)) { if (provider == null) { TraceLog.WriteError("Not found db connection of {0} entity.", receiveParam.Schema.EntityName); return(false); } var filter = new DbDataFilter(maxCount); if (!string.IsNullOrEmpty(personalId)) { filter.Condition = provider.FormatFilterParam(paramName); filter.Parameters.Add(paramName, personalId); } receiveParam.DbFilter = filter; } return(TryLoadCache(personalId, receiveParam, periodTime, false)); }
/// <summary> /// 尝试接收数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns>return null is load error</returns> public bool TryReceiveData <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { dataList = null; bool hasDbConnect = DbConnectionProvider.CreateDbProvider(receiveParam.Schema) != null; var schema = receiveParam.Schema; //表为空时,不加载数据 if (schema == null || string.IsNullOrEmpty(schema.EntityName)) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } //配置库不放到Redis,尝试从DB加载 if (schema.StorageType.HasFlag(StorageType.ReadOnlyDB) || schema.StorageType.HasFlag(StorageType.ReadWriteDB)) { if (!hasDbConnect) { dataList = new List <T>(); return(true); } var result = _dbTransponder.TryReceiveData(receiveParam, out dataList); TraceLog.ReleaseWriteDebug("The readonly-data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(result); } if (schema.StorageType.HasFlag(StorageType.ReadOnlyRedis) || schema.StorageType.HasFlag(StorageType.ReadWriteRedis)) { if (!string.IsNullOrEmpty(receiveParam.RedisKey) && _redisTransponder.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count > 0) { TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(true); } //从Redis历史记录表中加载 if (hasDbConnect && Setting != null && Setting.IsStorageToDb) { var result = TryLoadHistory(receiveParam.RedisKey, out dataList); TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1} from history.", receiveParam.RedisKey, dataList.Count); return(result); } dataList = new List <T>(); return(true); } //read faild from redis. return(false); } return(true); }
private bool OnLoad(DbDataFilter filter) { var redisKey = CreateRedisKey(); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); receiveParam.DbFilter = filter; receiveParam.Capacity = filter.Capacity == 0 ? 0 : receiveParam.Schema.Capacity; int periodTime = receiveParam.Schema == null ? 0 : receiveParam.Schema.PeriodTime; return(TryLoadCache(receiveParam, periodTime)); }
/// <summary> /// 加载数据 /// </summary> /// <param name="groupKey"></param> /// <param name="dataFilter"></param> /// <param name="periodTime"></param> /// <returns></returns> protected bool TryLoadCache(string groupKey, DbDataFilter dataFilter, int periodTime) { string redisKey = CreateRedisKey(groupKey); SchemaTable schema; if (EntitySchemaSet.TryGet <T>(out schema)) { TransReceiveParam receiveParam = new TransReceiveParam(redisKey, schema, dataFilter.Capacity, dataFilter); return(TryLoadCache(groupKey, receiveParam, periodTime)); } return(false); }
/// <summary> /// 尝试从数据库中加载数据,并更新到Redis /// </summary> /// <returns></returns> public bool TryLoadFromDb <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { if (_dbTransponder.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count > 0) { //恢复到Redis return(RedisConnectionPool.TryUpdateEntity(dataList)); } return(true); } return(false); }
/// <summary> /// 从Redis加载所有缓存 /// </summary> /// <param name="match"></param> public void LoadFrom(Predicate <T> match) { string redisKey = CreateRedisKey(); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); int maxCount = receiveParam.Schema.Capacity; var filter = new DbDataFilter(maxCount); receiveParam.DbFilter = filter; receiveParam.Capacity = maxCount; LoadFrom(receiveParam, match); }
/// <summary> /// 尝试从数据库中加载数据,并更新到Redis /// </summary> /// <returns></returns> public bool TryLoadFromDb <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { if (_dbTransponder.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count > 0) { TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1} from db.", receiveParam.RedisKey, dataList.Count); //load to Redis return(RedisConnectionPool.TryUpdateEntity(dataList)); } return(true); } return(false); }
/// <summary> /// 尝试从DB中恢复数据 /// </summary> /// <param name="filter"></param> /// <param name="personalId"></param> /// <returns></returns> public bool TryRecoverFromDb(DbDataFilter filter, string personalId = "") { List <T> dataList; string redisKey = CreateRedisKey(personalId); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); receiveParam.DbFilter = filter; if (DataContainer.TryRecoverFromDb(receiveParam, out dataList)) { return(InitCache(dataList, receiveParam.Schema.PeriodTime)); } return(false); }
/// <summary> /// 加载数据 /// </summary> /// <param name="groupKey"></param> /// <param name="receiveParam"></param> /// <param name="periodTime">缓存的生命周期,单位秒</param> /// <returns></returns> protected bool TryLoadCache(string groupKey, TransReceiveParam receiveParam, int periodTime) { CacheItemSet itemSet = InitContainer(groupKey, periodTime); List <T> dataList; if (DataContainer.TryReceiveData(receiveParam, out dataList)) { InitCache(dataList, periodTime); itemSet.OnLoadSuccess(); return(true); } itemSet.OnLoadError(); TraceLog.WriteError("Try load cache data:{0} error.", typeof(T).FullName); return(false); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="isReplace"></param> /// <returns></returns> protected override bool LoadItemFactory(string key, bool isReplace) { string redisKey = CreateRedisKey(key); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); int periodTime = receiveParam.Schema.PeriodTime; if (receiveParam.Schema.StorageType.HasFlag(StorageType.ReadOnlyRedis) || receiveParam.Schema.StorageType.HasFlag(StorageType.ReadWriteRedis)) { return(TryLoadRankCache(key, receiveParam, periodTime, isReplace)); } return(false); }
/// <summary> /// 加载Enity数据 /// </summary> /// <param name="receiveParam"></param> /// <param name="periodTime"></param> /// <returns></returns> protected bool TryLoadCache(TransReceiveParam receiveParam, int periodTime) { List <T> dataList; if (DataContainer.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count == 0) { return(true); } TraceLog.ReleaseWrite("The data:\"{0}\" has been loaded {1}.", DataContainer.RootKey, dataList.Count); return(InitCache(dataList, periodTime)); } TraceLog.WriteError("Try load cache data:{0} error.", receiveParam.Schema.EntityType.FullName); return(false); }
/// <summary> /// 尝试接收数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns>return null is load error</returns> public bool TryReceiveData <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { dataList = null; //表为空时,不加载数据 if (receiveParam.Schema == null || string.IsNullOrEmpty(receiveParam.Schema.EntityName) || DbConnectionProvider.CreateDbProvider(receiveParam.Schema) == null) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } //配置库不放到Redis,尝试从DB加载 if (receiveParam.Schema.AccessLevel == AccessLevel.ReadOnly) { var result = _dbTransponder.TryReceiveData(receiveParam, out dataList); TraceLog.ReleaseWriteDebug("The readonly-data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(result); } if (!string.IsNullOrEmpty(receiveParam.RedisKey) && _redisTransponder.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count > 0) { TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(true); } //从Redis历史记录表中加载 if (Setting != null && Setting.IsStorageToDb && TryLoadHistory(receiveParam.RedisKey, out dataList)) { //modify reason:数据不同步时改为在业务自己显示恢复 //Share类型的如果没有数据尝试从DB中取 //if (dataList.Count == 0 && receiveParam.Schema.CacheType == CacheType.Entity) //{ // return TryLoadFromDb(receiveParam, out dataList); //} TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1} from history.", receiveParam.RedisKey, dataList.Count); return(true); } return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="receiveParam"></param> /// <param name="match"></param> protected void LoadFrom(TransReceiveParam receiveParam, Predicate <T> match) { List <T> dataList = DataContainer.LoadFrom <T>(receiveParam); if (DataContainer.LoadStatus == LoadingStatus.Success && dataList != null) { int periodTime = receiveParam.Schema.PeriodTime; var tempList = match == null ? dataList : dataList.FindAll(match); var pairs = tempList.GroupBy(t => t.PersonalId).ToList(); foreach (var pair in pairs) { CacheItemSet itemSet = InitContainer(pair.Key, periodTime); InitCache(pair.ToList(), periodTime); itemSet.OnLoadSuccess(); } } }
/// <summary> /// 尝试从DB中恢复数据 /// </summary> /// <param name="filter"></param> /// <param name="personalId"></param> /// <returns></returns> public bool TryRecoverFromDb(DbDataFilter filter, string personalId = "") { List <T> dataList; if (!string.IsNullOrEmpty(personalId)) { personalId = AbstractEntity.EncodeKeyCode(personalId); } string redisKey = CreateRedisKey(personalId); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); receiveParam.DbFilter = filter; if (DataContainer.TryRecoverFromDb(receiveParam, out dataList)) { return(InitCache(dataList, receiveParam.Schema.PeriodTime, true)); } return(false); }
/// <summary> /// 处理加载数据参数 /// </summary> /// <param name="personalId"></param> /// <returns></returns> protected bool ProcessLoadParam(string personalId) { string redisKey = CreateRedisKey(personalId); TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = SchemaTable(); string paramName = receiveParam.Schema.PersonalName; int periodTime = receiveParam.Schema.PeriodTime; int maxCount = receiveParam.Schema.Capacity; var provider = DbConnectionProvider.CreateDbProvider(receiveParam.Schema); if (provider != null) { var filter = new DbDataFilter(maxCount); filter.Condition = provider.FormatFilterParam(paramName); filter.Parameters.Add(paramName, personalId); receiveParam.DbFilter = filter; } receiveParam.Capacity = maxCount; return(TryLoadCache(personalId, receiveParam, periodTime)); }
/// <summary> /// 加载Enity数据 /// </summary> /// <param name="receiveParam"></param> /// <param name="periodTime"></param> /// <returns></returns> protected bool TryLoadCache(TransReceiveParam receiveParam, int periodTime) { try { List <T> dataList; if (DataContainer.TryReceiveData(receiveParam, out dataList)) { if (dataList.Count == 0) { return(true); } return(InitCache(dataList, periodTime)); } TraceLog.WriteError("Try load cache data:{0} error.", receiveParam.Schema.EntityType.FullName); } catch (Exception ex) { string name = receiveParam.Schema != null ? receiveParam.Schema.EntityName : ""; TraceLog.WriteError("Try load cache \"{0}\" data error:{1}", name, ex); } return(false); }
/// <summary> /// 尝试从DB中恢复数据 /// </summary> /// <typeparam name="V"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns></returns> public bool TryRecoverFromDb <V>(TransReceiveParam receiveParam, out List <V> dataList) where V : AbstractEntity, new() { return(_cachePool.TryLoadFromDb(receiveParam, out dataList)); }
/// <summary> /// 尝试接收数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns>return null is load error</returns> public bool TryReceiveData <T>(TransReceiveParam receiveParam, out List <T> dataList) where T : AbstractEntity, new() { //todo:Trace //var watch = RunTimeWatch.StartNew("Cache load " + receiveParam.RedisKey); dataList = null; bool hasDbConnect = DbConnectionProvider.CreateDbProvider(receiveParam.Schema) != null; var schema = receiveParam.Schema; //表为空时,不加载数据 if (schema == null || string.IsNullOrEmpty(schema.EntityName)) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } //配置库不放到Redis,尝试从DB加载 if (schema.StorageType.HasFlag(StorageType.ReadOnlyDB) || schema.StorageType.HasFlag(StorageType.ReadWriteDB)) { if (!hasDbConnect) { dataList = new List <T>(); return(true); } if (_dbTransponder.TryReceiveData(receiveParam, out dataList)) { //TraceLog.ReleaseWriteDebug("The readonly-data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(true); } TraceLog.WriteError("The data:{0} loaded from db fail.\r\n{1}", receiveParam.RedisKey, TraceLog.GetStackTrace()); return(false); } if (schema.StorageType.HasFlag(StorageType.ReadOnlyRedis) || schema.StorageType.HasFlag(StorageType.ReadWriteRedis)) { //watch.Check("init"); if (!string.IsNullOrEmpty(receiveParam.RedisKey) && _redisTransponder.TryReceiveData(receiveParam, out dataList)) { //watch.Check("loaded"); if (dataList.Count > 0) { //watch.Flush(true); //TraceLog.ReleaseWriteDebug("The data:{0} has been loaded {1}", receiveParam.RedisKey, dataList.Count); return(true); } //从Redis历史记录表中加载 if (hasDbConnect && Setting != null && Setting.IsStorageToDb) { var result = TryLoadHistory(receiveParam.RedisKey, out dataList); TraceLog.Write("The data:{0} has been loaded {1} from history.", receiveParam.RedisKey, dataList.Count); return(result); } //watch.Flush(true); dataList = new List <T>(); return(true); } //read faild from redis. TraceLog.WriteError("The data:{0} loaded from redis fail.\r\n{1}", receiveParam.RedisKey, TraceLog.GetStackTrace()); return(false); } return(true); }
public bool TryLoadHistory <T>(string redisKey, out List <T> dataList) { redisKey = RedisConnectionPool.GetRedisEntityKeyName(redisKey); bool result = false; dataList = null; SchemaTable schemaTable; if (EntitySchemaSet.TryGet <EntityHistory>(out schemaTable)) { try { var provider = DbConnectionProvider.CreateDbProvider(schemaTable); if (provider == null) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = schemaTable; int maxCount = receiveParam.Schema.Capacity; var filter = new DbDataFilter(maxCount); string key = schemaTable.Keys[0]; filter.Condition = provider.FormatFilterParam(key); filter.Parameters.Add(key, redisKey); receiveParam.DbFilter = filter; receiveParam.Capacity = maxCount; List <EntityHistory> historyList; if (_dbTransponder.TryReceiveData(receiveParam, out historyList)) { EntityHistory history = historyList.Count > 0 ? historyList[0] : null; if (history != null && history.Value != null && history.Value.Length > 0) { byte[][] bufferBytes = ProtoBufUtils.Deserialize <byte[][]>(history.Value); byte[][] keys = bufferBytes.Where((b, index) => index % 2 == 0).ToArray(); byte[][] values = bufferBytes.Where((b, index) => index % 2 == 1).ToArray(); RedisConnectionPool.Process(client => client.HMSet(redisKey, keys, values)); dataList = values.Select(value => ProtoBufUtils.Deserialize <T>(value)).ToList(); result = true; } else { dataList = new List <T>(); result = true; } } } catch (Exception ex) { TraceLog.WriteError("Try load Redis's history key:{0}\r\nerror:{1}", redisKey, ex); } } else { dataList = new List <T>(); result = true; } return(result); }
public bool TryLoadHistory <T>(string redisKey, out List <T> dataList) { bool result = false; dataList = null; SchemaTable schemaTable; if (EntitySchemaSet.TryGet <EntityHistory>(out schemaTable)) { try { var provider = DbConnectionProvider.CreateDbProvider(schemaTable); if (provider == null) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } TransReceiveParam receiveParam = new TransReceiveParam(redisKey); receiveParam.Schema = schemaTable; int maxCount = receiveParam.Schema.Capacity; var filter = new DbDataFilter(maxCount); string key = schemaTable.Keys[0]; filter.Condition = provider.FormatFilterParam(key); filter.Parameters.Add(key, redisKey); receiveParam.DbFilter = filter; receiveParam.Capacity = maxCount; List <EntityHistory> historyList; if (_dbTransponder.TryReceiveData(receiveParam, out historyList)) { if (historyList.Count == 0) { dataList = new List <T>(); result = true; } else { EntityHistory history = historyList[0]; RedisManager.Process(client => client.Set(redisKey, history.Value)); var dataSet = ProtoBufUtils.Deserialize <Dictionary <string, T> >(history.Value); if (dataSet != null) { dataList = dataSet.Values.ToList(); result = true; } } } } catch (Exception ex) { TraceLog.WriteError("Try load Redis's history key:{0}\r\nerror:{1}", redisKey, ex); } } else { dataList = new List <T>(); result = true; } return(result); }
/// <summary> /// 从历史库中加载数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="redisKey"></param> /// <param name="dataList"></param> /// <returns></returns> public bool TryLoadHistory <T>(string redisKey, out List <T> dataList) where T : ISqlEntity { string[] entityAndKeys = (redisKey ?? "").Split('_'); var entityKey = entityAndKeys.Length > 1 ? entityAndKeys[1] : null; string entityNameKey = RedisConnectionPool.GetRedisEntityKeyName(entityAndKeys[0]); bool result = false; dataList = null; SchemaTable schemaTable; if (EntitySchemaSet.TryGet <EntityHistory>(out schemaTable)) { try { var provider = DbConnectionProvider.CreateDbProvider(schemaTable); if (provider == null) { //DB is optional and can no DB configuration dataList = new List <T>(); return(true); } TransReceiveParam receiveParam = new TransReceiveParam(entityNameKey); receiveParam.Schema = schemaTable; int maxCount = receiveParam.Schema.Capacity; var filter = new DbDataFilter(maxCount); string key = schemaTable.Keys[0]; var entitySchema = EntitySchemaSet.Get(entityAndKeys[0]); if (entitySchema != null && entitySchema.Keys.Length == 1) { filter.Condition = provider.FormatFilterParam(key); filter.Parameters.Add(key, string.Format("{0}_{1}", entityNameKey, entityKey)); } else { filter.Condition = provider.FormatFilterParam(key, "LIKE"); filter.Parameters.Add(key, string.Format("{0}_%{1}%", entityNameKey, entityKey)); } receiveParam.DbFilter = filter; List <EntityHistory> historyList; if (_dbTransponder.TryReceiveData(receiveParam, out historyList)) { if (historyList.Count == 0) { dataList = new List <T>(); return(true); } dataList = new List <T>(); var keyBytes = new byte[historyList.Count][]; var valueBytes = new byte[historyList.Count][]; for (int i = 0; i < keyBytes.Length; i++) { var entityHistory = historyList[i]; keyBytes[i] = RedisConnectionPool.ToByteKey(entityHistory.Key.Split('_')[1]); valueBytes[i] = entityHistory.Value; dataList.Add((T)_serializer.Deserialize(entityHistory.Value, typeof(T))); } //从DB备份中恢复到Redis, 多个Key时也要更新 var entitys = dataList.ToArray(); RedisConnectionPool.Process(client => { client.HMSet(entityNameKey, keyBytes, valueBytes); if (entitySchema.Keys.Length > 1) { RedisConnectionPool.UpdateFromMutilKeyMap <T>(client, entityKey, entitys); } }); result = true; } } catch (Exception ex) { TraceLog.WriteError("Try load Redis's history key:{0}\r\nerror:{1}", entityNameKey, ex); } } else { dataList = new List <T>(); result = true; } return(result); }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <param name="receiveParam"></param> /// <param name="dataList"></param> /// <returns></returns> public bool TryReceiveData <V>(TransReceiveParam receiveParam, out List <V> dataList) where V : AbstractEntity, new() { return(_cachePool.TryReceiveData(receiveParam, out dataList)); }