/// <summary> /// DecrementStats /// </summary> /// <param name="statsType">Model.StatsType.*</param> /// <param name="slotType"></param> /// <param name="slotId"></param> /// <param name="placeId"></param> /// <returns></returns> public virtual async Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId) { var time = new DateTimeOffset(slotId, TimeSpan.Zero); var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), };/**/ var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; return(await redisCacheClient.Db0.HashGetAsync <long?>( $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}", keyPlace )); }
/// <summary> /// DecrementStats /// </summary> /// <param name="statsType">Model.StatsType.*</param> /// <param name="slotType"></param> /// <param name="time"></param> /// <param name="placeId"></param> /// <returns></returns> public virtual async Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time) { var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), }; var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; return(await redisCacheClient.Db0.HashIncerementByAsync( $"{configuration["db-prefix"]}{REDIS_KEY_SLOT_STATS}", keyPlace, -1 )); }
/// <summary> /// Return stats for specific place and time /// </summary> /// <param name="statsType"></param> /// <param name="slotType"></param> /// <param name="placeId"></param> /// <param name="slotId"></param> /// <returns></returns> public async override Task <long?> GetStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, long slotId) { var time = new DateTimeOffset(slotId, TimeSpan.Zero); var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), };/**/ var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; if (Stats.ContainsKey(keyPlace)) { return(Stats[keyPlace]); } return(0); }
/// <summary> /// Decrement stats /// </summary> /// <param name="statsType"></param> /// <param name="slotType"></param> /// <param name="placeId"></param> /// <param name="time"></param> /// <returns></returns> public async override Task <long> DecrementStats(StatsType.Enum statsType, SlotType.Enum slotType, string placeId, DateTimeOffset time) { var t = slotType switch { SlotType.Enum.Day => time.RoundDay(), SlotType.Enum.Hour => time.RoundHour(), SlotType.Enum.Min => time.RoundMinute(), _ => throw new Exception("Invalid slot type"), }; var keyPlace = $"{StatsType.ToText(statsType)}-slot-{SlotType.ToText(slotType)}-{placeId}-{t}"; if (!Stats.ContainsKey(keyPlace)) { Stats[keyPlace] = 0; } Stats[keyPlace]--; return(Stats[keyPlace]); }