Exemple #1
0
        private static CustUserInfo GetPersonInfo(string userid, List <CustUserInfo> userinfos)
        {
            var          userKey = string.Format(Redis_UserId, userid);
            CustUserInfo person  = null;

            var user = string.Empty;

            if (WoyaopaoConfig.UseRedis)
            {
                user = AliRedisClient.getRedisConn().GetDatabase().StringGet(userKey);
            }

            if (string.IsNullOrWhiteSpace(user))
            {
                var userinfo = userinfos.Where(s => s.userid == userid).FirstOrDefault();
                if (userinfo != null)
                {
                    person = userinfo;
                    if (WoyaopaoConfig.UseRedis)
                    {
                        AliRedisClient.getRedisConn().GetDatabase().StringSet(userKey, JsonConvert.SerializeObject(person));
                    }
                }
            }
            else
            {
                person = JsonConvert.DeserializeObject <CustUserInfo>(user);
            }
            return(person);
        }
Exemple #2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //clean cache
            if (WoyaopaoConfig.UseRedis)
            {
                AliRedisClient.getRedisConn().GetDatabase().StringSet(WoyaopaoConfig.Redis_sourceDataKey, string.Empty);
            }
        }
Exemple #3
0
 public static void GetsourceFromRedis()
 {
     try
     {
         var sourceKey = Redis_sourceDataKey;
         var result    = AliRedisClient.getRedisConn().GetDatabase().StringGet(sourceKey);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error:" + ex.Message);
         Logger.Default.Error(ex);
     }
 }
Exemple #4
0
        public static void Setsource()
        {
            try
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " start get source data");
                var source = GetDataFromSource();
                Console.WriteLine("geted");
                var entity = source2Transfer(source);
                Console.WriteLine("transfer");
                var json = JsonConvert.SerializeObject(entity);
                Console.WriteLine("write into redis");
                var sourceKey = Redis_sourceDataKey;
                AliRedisClient.getRedisConn().GetDatabase().StringSet(sourceKey, json);
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " end");

                Console.WriteLine("*********************************");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:" + ex.Message);
                Logger.Default.Error(ex);
            }
        }
Exemple #5
0
        public ActionResult GetsourceData()
        {
            try
            {
                var sourceFromRedis = false;
                if (WoyaopaoConfig.UseRedis)
                {
                    var result = AliRedisClient.getRedisConn().GetDatabase().StringGet(WoyaopaoConfig.Redis_sourceDataKey);
                    if (string.IsNullOrWhiteSpace(result))
                    {
                        var source = FubanPlatform.GetDataFromSource();

                        var entity = FubanPlatform.source2Transfer(source);
                        var json   = JsonConvert.SerializeObject(entity);
                        AliRedisClient.getRedisConn().GetDatabase().StringSet(WoyaopaoConfig.Redis_sourceDataKey, json, new TimeSpan(WoyaopaoConfig.Woyaopao_source_Timespan));
                        return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        sourceFromRedis = true;
                        var entity = JsonConvert.DeserializeObject <CustPageInfo>(result);
                        return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    var source = FubanPlatform.GetDataFromSource();

                    var entity = FubanPlatform.source2Transfer(source);
                    return(Json(new { sourceFromRedis = sourceFromRedis, Data = entity }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Msg = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }