public static Result <RedisClusterSize> TryParse(string clusterSize) { if (string.IsNullOrEmpty(clusterSize)) { return(new Result <RedisClusterSize>(errorMessage: $"Empty string can't be parsed into {nameof(RedisClusterSize)}")); } var parts = clusterSize.Split(new string[] { "/" }, StringSplitOptions.None); if (parts.Length != 2) { return(new Result <RedisClusterSize>(errorMessage: $"Failed to split {nameof(RedisClusterSize)} from `{clusterSize}`: {string.Join(", ", parts)}")); } var redisTierResult = RedisTier.TryParse(parts[0]); if (!redisTierResult.Succeeded) { return(new Result <RedisClusterSize>(redisTierResult)); } var redisTier = redisTierResult.Value; Contract.AssertNotNull(redisTier); if (!int.TryParse(parts[1], out var shards)) { return(new Result <RedisClusterSize>(errorMessage: $"Failed to obtain number of shards from `{parts[1]}`")); } return(new RedisClusterSize(redisTier, shards)); }
public static bool CanScale(RedisTier from, RedisTier to) { if (from.Equals(to)) { return(true); } if (!CanScale(from.Plan, to.Plan)) { return(false); } // You can't scale from a larger size down to the C0 (250 MB) size if ((to.Plan == RedisPlan.Basic || to.Plan == RedisPlan.Standard) && to.Capacity == 0) { return(false); } // You can scale the plan, but you can't simultaneously change the capacity if (!from.Plan.Equals(to.Plan)) { return(from.Capacity == to.Capacity); } return(true); }
public static bool CanScale(RedisTier from, RedisTier to) { if (from.Equals(to)) { return(true); } if (!CanScale(from.Plan, to.Plan)) { return(false); } // You can scale from a Basic cache to a Standard cache but you can't change the size at the same time if (from.Plan == RedisPlan.Basic && to.Plan == RedisPlan.Standard) { return(from.Capacity == to.Capacity); } // You can't scale from a larger size down to the C0 (250 MB) size if ((to.Plan == RedisPlan.Basic || to.Plan == RedisPlan.Standard) && to.Capacity == 0) { return(false); } return(true); }
public RedisClusterSize(RedisTier tier, int shards) { Contract.Requires(1 <= shards && shards <= 10, "Number of shards out of bounds, must be between 1 and 10"); Tier = tier; Shards = shards; _scaleEligibleSizes = new Lazy <IReadOnlyList <RedisClusterSize> >(() => Instances.Where(to => RedisScalingUtilities.CanScale(this, to)).ToList(), System.Threading.LazyThreadSafetyMode.PublicationOnly); }
public static bool IsDownScale(RedisTier from, RedisTier to) { // Premium to Standard is a downscale, as well as Standard to basic and transitive. if (from.Plan > to.Plan) { return(true); } if (from.Plan < to.Plan) { return(false); } // Plans are equal, so all we care about is instance capacity return(from.Capacity > to.Capacity); }