public void RemovePromotionSku(string redisNo, string spu, string sku) { var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >( "SFO2O.SJ_" + redisNo, "", () => { return(new List <RedisPromotionSpuModel>()); }); var spuModel = model.FirstOrDefault(p => p.Spu == spu); if (spuModel != null) { spuModel.AddTime = DateTime.Now; var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku); if (skuModel != null) { spuModel.Skus.Remove(skuModel); } } if (spuModel.Skus.Count == 0) { model.Remove(spuModel); } RedisCacheHelper.Add("SFO2O.SJ_" + redisNo, model, 30); }
public static object GetProductListNew() { const int cacheTime = 2; const string cacheKey = "product_list"; const string lockKey = cacheKey; var cacheValue = RedisCacheHelper.Get <string>(cacheKey); if (cacheValue != null) { // Console.WriteLine("从Redis中读取"); return(cacheValue); } else { lock (lockKey) { cacheValue = RedisCacheHelper.Get <string>(cacheKey); if (cacheValue != null) { return(cacheValue); } else { cacheValue = "1111"; //这里一般是 sql查询数据。 Console.WriteLine("从数据库中读取"); RedisCacheHelper.Add(cacheKey, cacheValue, DateTime.Now.AddSeconds(cacheTime)); } } return(cacheValue); } }
/// <summary> /// 获取行业类型描述列表 /// </summary> /// <param name="key"></param> /// <returns></returns> public static IList <DicsModel> GetDicsInfoByKey(string key) { try { // 全部的Dics IList <DicsModel> lstDics = RedisCacheHelper.Get <List <DicsModel> >(keyDicsInfo); if (lstDics == null || lstDics.Where(p => String.IsNullOrWhiteSpace(p.KeyName)).Count() > 0) { lstDics = new DicsBLL().GetAllDicsInfo(); RedisCacheHelper.Add(keyDicsInfo, lstDics, 60); } // 根据DicsType 获取相关的字典属性 var result = (from n in lstDics where n.DicType == key && n.LanguageVersion == (int)LanguageEnum.TraditionalChinese select n).ToList <DicsModel>(); return(result); } catch { return(null); } }
public dynamic GetAuthorizationCode(string code, string state, string clientId, string redirectUri = "") { string redisCode = RedisCacheHelper.Get <string>(tenantId, "GetCode" + clientId) ?? ""; returnData.Note = state; if (string.IsNullOrEmpty(redisCode)) { returnData.Massage = "code过期"; return(returnData); } if (!redisCode.Equals(code)) { returnData.Massage = "code有误"; return(returnData); } string accesstoken = Guid.NewGuid().ToString("N"); returnData.Massage = accesstoken; RedisCacheHelper.Add(tenantId, "GetAuthorizationCode" + clientId, accesstoken, DateTime.Now.AddMinutes(accesstokenValidTime)); RedisCacheHelper.Remove(tenantId, "GetCode" + clientId); if (!string.IsNullOrEmpty(redirectUri)) { HttpContext.Current.Response.Redirect(redirectUri + "?code=" + code + "&state=" + state, true); } return(returnData); }
public static IList <DicsModel> GetDicsInfoByKeyAllLanguage(string key) { try { // 全部的Dics IList <DicsModel> lstDics = RedisCacheHelper.Get <List <DicsModel> >(keyDicsInfo); if (lstDics == null) { lstDics = new DicsBLL().GetAllDicsInfo(); RedisCacheHelper.Add(keyDicsInfo, lstDics, 60); } // 根据DicsType 获取相关的字典属性 var result = (from n in lstDics where n.DicType == key select n).ToList <DicsModel>(); return(result); } catch { return(null); } }
public static object GetProductListNew() { const int cacheTime = 30; const string cacheKey = "product_list"; //缓存标记。 const string cacheSign = cacheKey + "_sign"; var sign = RedisCacheHelper.Get <string>(cacheSign); //获取缓存值 var cacheValue = RedisCacheHelper.Get <string>(cacheKey); if (sign != null) { return(cacheValue); //未过期,直接返回。 } else { RedisCacheHelper.Add(cacheSign, "1", DateTime.Now.AddSeconds(cacheTime)); ThreadPool.QueueUserWorkItem((arg) => { cacheValue = "2222"; //这里一般是 sql查询数据。 RedisCacheHelper.Add(cacheKey, cacheValue, DateTime.Now.AddSeconds(cacheTime * 2)); //日期设缓存时间的2倍,用于脏读。 }); return(cacheValue); } }
private void Recive_Client(string msg, string stname) { string[] cmd = msg.Split(','); switch (cmd[0]) { case "ReadName": SendMsgToClient(stname, RedisCacheHelper.Get <string>("OPTest_Name")); break; case "ReadAge": SendMsgToClient(stname, RedisCacheHelper.Get <string>("OPTest_Age")); break; case "WriteName": RedisCacheHelper.Add <string>("OPTest_Name", cmd[1]); SendMsgToClient(stname, "WriteNameOK"); break; case "WriteAge": RedisCacheHelper.Add <string>("OPTest_Age", cmd[1]); SendMsgToClient(stname, "WriteAgeOK"); break; } }
/// <summary> /// 创建缓存数据 /// </summary> /// <param name="list"></param> /// <returns></returns> public static string CreateCache(string key, dynamic str) { lock (StaticLock.TokenLock) { RedisCacheHelper.Add($"{key}", str, DateTime.Now.AddMinutes(3)); return(key); } }
public static void Cache(HttpSessionStateBase Session, LoginUserModel longinuser) { string cacheKey = GetCacheKey(longinuser.SupplierUserInfo.ID.ToString()); Session[SessionKey] = longinuser.SupplierUserInfo.ID; longinuser.SupplierUserInfo.UserID = longinuser.SupplierUserInfo.ID; longinuser.SupplierUserInfo.CacheTime = DateTime.Now; RedisCacheHelper.Add <LoginUserModel>(cacheKey, longinuser, DateTime.Now.AddMinutes(Session.Timeout)); }
public static void Cache(LoginUserModel longinuser) { var Session = HttpContext.Current.Session; string cacheKey = GetCacheKey(longinuser.AdminUserInfo.id); Session[SessionKey] = longinuser.AdminUserInfo.id; longinuser.AdminUserInfo.CacheTime = DateTime.Now; RedisCacheHelper.Add <LoginUserModel>(cacheKey, longinuser, DateTime.Now.AddMinutes(Session.Timeout)); }
public dynamic GetTokenByClient() { int clientId = 1; string token = Guid.NewGuid().ToString("N"); returnData.Massage = token; RedisCacheHelper.Add(tenantId, "GetAuthorizationCode" + clientId, token, DateTime.Now.AddMinutes(accesstokenValidTime)); return(returnData); }
/// <summary> /// 创建Token /// </summary> /// <param name="qjUser"></param> /// <returns></returns> public static string CreateToken(QjCurrentUser qjUser) { lock (StaticLock.TokenLock) { var token = Guid.NewGuid().ToString("N"); RedisCacheHelper.Add($"{StaticLock.UserRedisKeyPrefix}{token}", qjUser, DateTime.Now.AddSeconds(86400)); return(token); } }
public void RedisAdd() { DateTime dtime = new DateTime(2019, 03, 10); RedisCacheHelper.Add <string>("kim2", "test", dtime); string str = RedisCacheHelper.Get <string>("kim2"); Assert.AreEqual("test", str); }
/// <summary> /// 初始化秒杀商品 /// </summary> public static void InitProductSecKill() { var resp = MysqlHelper.ExecuteObjects <List <ProductDto> >("select * from Product"); RedisCacheHelper.Add <List <ProductDto> >("productlist", resp.Data, DateTime.Now.AddMinutes(30)); foreach (var item in resp.Data) { RedisCacheHelper.Add <int>(item.ID.ToString(), item.Count, DateTime.Now.AddMinutes(30)); } }
/* DI 容器测试 * static void Main(string[] args) * { * IServiceCollection services = new ServiceCollection() * .AddSingleton<IFoo, Foo>() * .AddSingleton<IBar>(new Bar()) * .AddSingleton<IBaz>(b => new Baz()) * .AddSingleton<IGux, Gux>(); * * IServiceProvider serviceProvider = services.BuildServiceProvider(); * * * Console.WriteLine("serviceProvider.GetService<IFoo>(): {0}", serviceProvider.GetService<IFoo>()); * Console.WriteLine("serviceProvider.GetService<IBar>(): {0}", serviceProvider.GetService<IBar>()); * Console.WriteLine("serviceProvider.GetService<IBaz>(): {0}", serviceProvider.GetService<IBaz>()); * Console.WriteLine("serviceProvider.GetService<IGux>(): {0}", serviceProvider.GetService<IGux>()); * * Console.ReadKey(); * } */ /// <summary> /// core的 configuration 配置调用 /// </summary> ///<param name="args"></param> static void Main(string[] args) { RedisCacheHelper.Add <string>("mystring", "123456", new TimeSpan(10000)); var redis = RedisCacheHelper.Get <string>("mystring"); Console.WriteLine(redis); Console.ReadKey(); }
public dynamic GetCode(string clientId, string state, string redirectUri = "", string scope = "") { string code = Guid.NewGuid().ToString("N"); returnData.Massage = code; returnData.Note = state; RedisCacheHelper.Add(tenantId, "GetCode" + clientId, code, DateTime.Now.AddMinutes(codeValidTime)); if (!string.IsNullOrEmpty(redirectUri)) { HttpContext.Current.Response.Redirect(redirectUri + "?code=" + code + "&state=" + state, true); } return(returnData); }
public dynamic GetToken(string clientId, string state, string redirectUri = "") { string token = Guid.NewGuid().ToString("N"); returnData.Massage = token; returnData.Note = state; RedisCacheHelper.Add(tenantId, "GetAuthorizationCode" + clientId, token, DateTime.Now.AddMinutes(accesstokenValidTime)); if (!string.IsNullOrEmpty(redirectUri)) { HttpContext.Current.Response.Redirect(redirectUri + "?token=" + token + "&state=" + state, true); } return(returnData); }
public void AddPromotionSku(string redisNo, string spu, string sku, decimal promotionPrice, decimal promotionRate) { var model = CacheHelper.AutoCache <List <RedisPromotionSpuModel> >( "SFO2O.SJ_" + redisNo, "", () => { return(new List <RedisPromotionSpuModel>()); }); var spuModel = model.FirstOrDefault(p => p.Spu == spu); if (spuModel != null) { spuModel.AddTime = DateTime.Now; var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku); if (skuModel != null) { skuModel.PromotionPrice = promotionPrice; skuModel.PromotionRate = promotionRate; } else { spuModel.Skus.Add(new RedisPromotionSkuModel() { PromotionPrice = promotionPrice, PromotionRate = promotionRate, sku = sku }); } } if (spuModel == null || spuModel.Skus == null) { spuModel = new RedisPromotionSpuModel(); spuModel.Skus = new List <RedisPromotionSkuModel>(); spuModel.Spu = spu; spuModel.AddTime = DateTime.Now; spuModel.Skus.Add(new RedisPromotionSkuModel() { PromotionPrice = promotionPrice, PromotionRate = promotionRate, sku = sku }); model.Add(spuModel); } RedisCacheHelper.Add("SFO2O.SJ_" + redisNo, model, 30); }
/// <summary> /// 设置用户登录后的session /// </summary> /// <param name="user"></param> public static void SetLoginUserSession(LoginUserModel user) { var session = HttpContext.Current.Session; session[ConstClass.SessionKeyMLoginUser] = user.UserID; RedisCacheHelper.Add(GetLoginUserRedisKey(user.UserID), user, DateTime.Now.AddMinutes(session.Timeout)); if (user.Status == 1) { CookieHelper.SetCookie(ConstClass.LoginUserCookieKey , dic: new Dictionary <string, string> { { "username", user.UserName }, { "Id", user.UserID.ToString() } }); } }
public static void RefreshSession(LoginUserModel user) { var session = HttpContext.Current.Session; if (user != null) { if (user.LoginTime.AddMinutes(session.Timeout - 5) < DateTime.Now) { RedisCacheHelper.Remove(GetLoginUserRedisKey(user.UserID)); session[ConstClass.SessionKeyMLoginUser] = null; session[ConstClass.SessionKeyMLoginUser] = user.UserID; //user.LoginTime = DateTime.Now; RedisCacheHelper.Add(GetLoginUserRedisKey(user.UserID), user, session.Timeout); } } }
public dynamic GetTokenByUser(string userName, string passWord) { int clientId = 0; if (userName == passWord) { clientId = 1; } else { returnData.Massage = "用户名密码有误(Test相同即可)"; return(returnData); } string token = Guid.NewGuid().ToString("N"); returnData.Massage = token; RedisCacheHelper.Add(tenantId, "GetAuthorizationCode" + clientId, token, DateTime.Now.AddMinutes(accesstokenValidTime)); return(returnData); }
/// <summary> /// 获取全部的商家信息 /// </summary> /// <returns></returns> public static Dictionary <int, string> GetSuppliers() { try { // 全部的Dics Dictionary <int, string> dicSuppliers = RedisCacheHelper.Get <Dictionary <int, string> >(keySupplierInfo); if (dicSuppliers == null) { dicSuppliers = new Supplier.SupplierBLL().GetSupplierNames(); RedisCacheHelper.Add(keyDicsInfo, dicSuppliers, 60); } return(dicSuppliers); } catch { return(null); } }
public ActionResult Index() { //var count = SQLHelper.ExecuteScalar("select COUNT(*) from Student"); //var data = SQLHelper.ExecuteDataTable("select * from Student"); //var countStudent = int.Parse(SQLHelper.ExecuteScalar("select COUNT(*) from Student where S#='10' ").ToString()); //if (countStudent > 0) //{ // var temp = SQLHelper.ExecuteNonQuery("delete from Student where S#='10' "); //} //var insert = SQLHelper.ExecuteNonQuery("insert into student (s#,Sname,Sage,Ssex) values('10','aaaa','1990-04-01 00:00:00.000','男')"); ViewData["message"] = "这是ViewData(string)" + IPHepler.GetLocalIP(); Student stu = new Student { Age = 320, Name = "潘守军3", NO = "NO003" }; //Student stu = new Student { Age = 10, Name = "潘守军", NO = "NO001" }//; ViewBag.ViewBagStu = stu; ViewData["ViewDataStu"] = stu; TempData["TempDataStu"] = stu; if (!RedisCacheHelper.Exists(stu.NO)) { RedisCacheHelper.Add <Student>(stu.NO, stu, DateTime.Now.AddMinutes(15)); } else { var student = RedisCacheHelper.Get <Student>("NO001"); } return(View()); }
private void Init() { ChannelName = ConfigurationManager.AppSettings["LineName"]; if (OPTestReceiveSlaveHandle == null) { OPTestReceiveSlaveHandle = Recive_OPTest; } OPTestReceiveSlaveHandle.BeginInvoke(null, null); if (OP01ReceiveSlaveHandle == null) { OP01ReceiveSlaveHandle = Recive_OP01; } OP01ReceiveSlaveHandle.BeginInvoke(null, null); if (RedisCacheHelper.Get <string>("OPTest_Name") == null || RedisCacheHelper.Get <string>("OPTest_Age") == null) { RedisCacheHelper.Add <string>("OPTest_Name", ""); RedisCacheHelper.Add <string>("OPTest_Age", ""); } }
static void Sync_vendor_code_func() { try { DbHelperSQL dbNet; var connectionString = ToolAPI.INIOperate.IniReadValue("netSqlGroup", "connectionString", Application.StartupPath + "\\Config.ini"); string[] connectionStringtearm = connectionString.Split('&'); if (connectionStringtearm != null && connectionStringtearm.Length == 5) { dbNet = new DbHelperSQL(string.Format("Data Source={0};Port={1};Database={2};User={3};Password={4}", connectionStringtearm[0], connectionStringtearm[1], connectionStringtearm[2], connectionStringtearm[3], connectionStringtearm[4]), DbProviderType.MySql); } else { dbNet = new DbHelperSQL(string.Format("Data Source={0};Port={1};Database={2};User={3};Password={4}", "172.24.108.167", "3306", "gd_db_v2", "wisdom_root", "JIwLi5j40SY#o1Et"), DbProviderType.MySql); } Dictionary <string, string> Equipment_project_temp = new Dictionary <string, string>(); string sql = "select distinct supplier_code,supplier_abbreviation from biz_supplier "; DataTable dt = dbNet.ExecuteDataTable(sql, null); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { string supplier_code = dr["supplier_code"].ToString(); string supplier_abbreviation = dr["supplier_abbreviation"].ToString(); //存入redis中 string key = "supplier_code:" + supplier_code; TimeSpan timeSpan = new TimeSpan(0, 0, 300); RedisCacheHelper.Add(key, supplier_abbreviation, timeSpan); } } } catch (Exception ex) { ToolAPI.XMLOperation.WriteLogXmlNoTail("Sync_vendor_code_func异常", ex.Message); } }
public int GetPromotionSkus(int promotionId, string redisNo) { var pSkus = new List <PromotionInfoModel>(); if (promotionId > 0) { pSkus = _bll.GetPromotionSkus(promotionId, this.CurrentUser.SupplierID); } if (pSkus.Count() > 0) { var spu = ""; List <RedisPromotionSpuModel> model = new List <RedisPromotionSpuModel>(); foreach (var sku in pSkus) { var spuModel = model.FirstOrDefault(p => p.Spu == sku.spu); if (spuModel != null) { var skuModel = spuModel.Skus.FirstOrDefault(p => p.sku == sku.Sku); if (skuModel != null) { skuModel.PromotionPrice = sku.DiscountPrice; skuModel.PromotionRate = sku.DiscountRate; } else { spuModel.Skus.Add(new RedisPromotionSkuModel() { PromotionPrice = sku.DiscountPrice, PromotionRate = sku.DiscountRate, sku = sku.Sku }); } } if (spuModel == null || spuModel.Skus == null) { spuModel = new RedisPromotionSpuModel(); spuModel.Skus = new List <RedisPromotionSkuModel>(); spuModel.Spu = sku.spu; spuModel.AddTime = sku.CreateTime; spuModel.Skus.Add(new RedisPromotionSkuModel() { PromotionPrice = sku.DiscountPrice, PromotionRate = sku.DiscountRate, sku = sku.Sku }); model.Add(spuModel); } } RedisCacheHelper.Add("SFO2O.SJ_" + redisNo, model, 30); } return(pSkus.Count()); }
/// <summary> /// 获取用户登录信息 /// </summary> /// <returns></returns> private LoginUserModel UserLogin(ActionExecutingContext filterContext) { var request = filterContext.HttpContext.Request; //获取登录信息 LoginUserModel loginUserModel = LoginHelper.GetCurrentUserInfo(); var userid = "" + Session[LoginHelper.SessionKey]; int id = 0; if (!string.IsNullOrEmpty(userid)) { int.TryParse(userid.ToString(), out id); } if (loginUserModel == null) { var loginKey = LoginHelper.GetCurrentCacheKey(); if (id > 0) { //从本地缓存中获取登录对象 loginUserModel = (LoginUserModel)HttpRuntime.Cache.Get(loginKey); } if (loginUserModel == null) { if (id == 0 || ShieldUsers.Contains(userid)) { filterContext.Result = Redirect(GetLoginUrl(filterContext.HttpContext.Request)); } else { loginUserModel = adminUserBLL.GetLoginUserByUserID(id); RedisCacheHelper.Add <LoginUserModel>(loginKey, loginUserModel, DateTime.Now.AddMinutes(Session.Timeout)); } } } else { /* 测试阶段暂时注销,待菜单稳定后打开 * * if (filterContext.HttpContext.Request.Url.AbsolutePath.Equals("/")) * return loginUserModel; * int urlHashCode = filterContext.HttpContext.Request.Url.AbsolutePath.GetHashCode(); * bool usable = false; * //安全验证,判断请求的URL是否属于用户权限菜单 * foreach (var item in loginUserModel.MenuList) * { * if (item.children != null) * { * foreach (var childMenu in item.children) * { * if (urlHashCode == childMenu.ModuleURL.GetHashCode()) * { * usable = true; * break; * } * } * * if (usable) * break; * } * } * * if (!usable) * { * filterContext.RequestContext.HttpContext.Response.Redirect("http://Admin.SFO2O.com/", true); * } */ } return(loginUserModel); }