internal static long GetSetScore(this IRedisObject setValue) { PropertyInfo prop; if (setValue is IProxyTargetAccessor) { prop = ((IProxyTargetAccessor)setValue).DynProxyGetTarget() .GetType() .GetProperties() .SingleOrDefault(p => p.HasAttribute <RedisSetOrderKey>()); } else { prop = setValue.GetType().GetProperties().SingleOrDefault(p => p.HasAttribute <RedisSetOrderKey>()); } if (prop == null) { throw new Exception("RedisOrderSetKey not found."); } var value = prop.GetValue(setValue, null); if (value is DateTime) { return(((DateTime)value).GetMillisecondsSinceEpoch()); } return((long)value); }
public static bool GetCommonData(this IRedisObject redisObject, out CommonData data) { if (!(redisObject is IProxyTargetAccessor)) { data = null; return(false); } data = ((IProxyTargetAccessor)redisObject).GetCommonData(); return(true); }
internal static object CreateProxy(this IRedisObject redisObect, CommonData commonData, out RedisKeyObject key) { var argumentType = redisObect.GetType(); key = new RedisKeyObject(argumentType, string.Empty); commonData.RedisDatabase.GenerateId(key, redisObect, commonData.RedisObjectManager.RedisBackup); var newArgument = commonData.RedisObjectManager.RetrieveObjectProxy(argumentType, key.Id, commonData.RedisDatabase, redisObect); return(newArgument); }
private object CreateProxy(IRedisObject argument, out RedisKeyObject key) { var argumentType = argument.GetType(); key = new RedisKeyObject(argumentType, string.Empty); _commonData.RedisDatabase.GenerateId(key, argument, _commonData.RedisObjectManager.RedisBackup); var newArgument = _commonData.RedisObjectManager.RetrieveObjectProxy(argumentType, key.Id, _commonData.RedisDatabase, argument); return(newArgument); }
static List <Employee> GetEmployees() { // check if result is in redis and also time valid IRedisObject result = RedisDataAccess.GetWithTimeStamp(LANDING_QUERY_REDIS_KEY); if (result == null || DateTime.Now.Subtract(result.LastUpdateTime).Minutes > 30) { List <Employee> employees = GetEmployeesFromDB(); string employeesJson = JsonConvert.SerializeObject(employees); RedisDataAccess.SaveWithTimeStamp(LANDING_QUERY_REDIS_KEY, employeesJson); return(employees); } else { return(JsonConvert.DeserializeObject <List <Employee> >(result.JsonData)); } }
public IList <FullFlightData> GetDepartingFlightsFullData() //insert redis here { IRedisObject result = RedisAccessLayer.GetWithTimeStamp(RedisConfig.GetDepartingFlightsFullData); if (result == null || DateTime.Now.Subtract(result.LastTimeUpdated).Minutes > 10) { IList <FullFlightData> fullFlightsData = _flightDAO.GetDepartingFlightsFullData(); // from DB string fullFlightDataJson = JsonConvert.SerializeObject(fullFlightsData); RedisAccessLayer.SaveWithTimeStamp(RedisConfig.GetDepartingFlightsFullData, fullFlightDataJson); return(fullFlightsData); } else { return(JsonConvert.DeserializeObject <List <FullFlightData> >(result.JsonData)); } //IList<FullFlightData> fullFlightsData = _flightDAO.GetDepartingFlightsFullData(); //return fullFlightsData; }
public static void DeleteRedisObject(this IRedisObject redisObject) { CommonData data; if (!redisObject.GetCommonData(out data)) { throw new Exception("Objects needs to be a Proxy (call RetrieveObjectProxy first)"); } data.Processing = true; var target = redisObject.GetTarget(); foreach (var prop in target.GetType().GetProperties()) { if (prop.HasAttribute <RedisDeleteCascade>()) { if (!prop.GetAttribute <RedisDeleteCascade>().Cascade) { continue; } } var value = prop.GetValue(redisObject, null); if (value is IRedisObject) { ((IRedisObject)value).DeleteRedisObject(); } } data.Processing = false; var key = new RedisKeyObject(redisObject.GetType(), string.Empty); data.RedisDatabase.GenerateId(key, redisObject, data.RedisObjectManager.RedisBackup); data.RedisDatabase.KeyDelete(key.RedisKey); data.RedisObjectManager.RedisBackup?.DeleteHash(key); }
private object CreateProxy(IRedisObject argument, out RedisKeyObject key) { var argumentType = argument.GetType(); key = new RedisKeyObject(argumentType, string.Empty); _commonData.RedisDatabase.GenerateId(key, argument, _commonData.RedisObjectManager.RedisBackup); var newArgument = _commonData.RedisObjectManager.RetrieveObjectProxy(argumentType, key.Id, _commonData.RedisDatabase, argument); return newArgument; }