using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json; using StackExchange.Redis; using ServerCore; using ServerBase; using META_ID = System.UInt32; namespace ServerCommon; public partial class CraftHelpCacheRequest : RedisRequestPrivateBase { public static readonly double CRAFT_CACHE_EXPIRY_TIME = ConstValue.default_1_day_to_sec * ConstValue.default_1_sec_to_milisec; private string m_target_guid; public CraftHelpCacheRequest(UserBase owner, RedisConnector redisConnector, string target_guid) : base(owner, redisConnector) { m_target_guid = target_guid; } public async Task UpsertCraftHelp(string push_Guid) { var result = new Result(); var err_msg = string.Empty; var limitCount = MetaHelper.GameConfigMeta.CraftingHelpLimitCountReceive; try { var database = getDatabase(); string craftHelpListKey = onMakeKey(); var pushAfterLength = await database.ListRightPushAsync(craftHelpListKey, push_Guid); if (pushAfterLength > limitCount) { await database.ListTrimAsync(craftHelpListKey, 0, limitCount - 1); var trimAfterPosition = await database.ListPositionAsync(craftHelpListKey, push_Guid); if (trimAfterPosition == -1) { err_msg = $"Crafting help receieved Count Over !!! : push_Guid :{push_Guid}- {getOwner().toBasicString()}"; result.setFail(ServerErrorCode.CraftingHelpReceivedCountOver, err_msg); Log.getLogger().error(err_msg); return result; } } if(pushAfterLength == 1) { await database.KeyExpireAsync(craftHelpListKey, TimeSpan.FromMilliseconds(CRAFT_CACHE_EXPIRY_TIME)); } return result; } catch (Exception e) { err_msg = $"Failed to set LoginCache in Redis !!! : : Exception:{e} - {getOwner().toBasicString()}"; result.setFail(ServerErrorCode.TryCatchException, err_msg); Log.getLogger().error(err_msg); return result; } } protected override string onMakeKey() { return $"craftHelp:{m_target_guid}:{DateTime.UtcNow.Date}"; } public override string toBasicString() { return $"craftHelp: In:UserGuid:{m_target_guid}"; } }