コード例 #1
0
        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);
        }
コード例 #2
0
        public static bool GetCommonData(this IRedisObject redisObject, out CommonData data)
        {
            if (!(redisObject is IProxyTargetAccessor))
            {
                data = null;
                return(false);
            }

            data = ((IProxyTargetAccessor)redisObject).GetCommonData();
            return(true);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: dotnet111119/22.06.2020
        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));
            }
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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;
        }