/// <summary> /// 是否连接成功 /// </summary> /// <returns></returns> public static bool IsConnectSuscess() { try { using (NewLife.Caching.Redis redis = GetClient()) { redis.Set <string>("TestRedis", "OK"); var redisvalue = redis.Get <string>("TestRedis"); } return(true); } catch (Exception ex) { return(false); } }
/// <summary> /// 获取单体 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public static T Get <T>(string key) where T : class { try { using (NewLife.Caching.Redis redis = GetClient()) { return(redis.Get <T>(key)); } } catch (Exception e) { retryflag++; if (5 < retryflag) { throw e; } using (NewLife.Caching.Redis redis = GetClient(1)) { return(redis.Get <T>(key)); } } }