123 lines
3.6 KiB
C#
123 lines
3.6 KiB
C#
using Microsoft.AspNetCore.DataProtection.KeyManagement;
|
|
using Newtonsoft.Json;
|
|
using ServerCore; using ServerBase;
|
|
using StackExchange.Redis;
|
|
using System.Numerics;
|
|
|
|
|
|
namespace ServerCommon.Cache;
|
|
|
|
public class QuestNotifyCache : CacheBase
|
|
{
|
|
[JsonProperty("quest_id")]
|
|
public UInt32 m_quest_id { get; set; } = 0;
|
|
|
|
[JsonProperty("quest_revision")]
|
|
public UInt32 m_quest_revision { get; set; } = 0;
|
|
|
|
public QuestNotifyCache(UInt32 questId, UInt32 questRevision)
|
|
{
|
|
m_quest_id = questId;
|
|
m_quest_revision = questRevision;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public class QuestNotifyCacheRequest : RedisRequestPrivateBase
|
|
{
|
|
public string m_user_guid { get; set; } = string.Empty;
|
|
public UInt32 m_quest_id { get; set; } = 0;
|
|
public UInt32 m_quest_revision { get; set; } = 0;
|
|
|
|
|
|
public QuestNotifyCacheRequest(UserBase owner, string userGuid, UInt32 quest_id, UInt32 quest_revision, RedisConnector redisConnector) : base(owner, redisConnector)
|
|
{
|
|
m_user_guid = userGuid;
|
|
m_quest_id = quest_id;
|
|
m_quest_revision = quest_revision;
|
|
}
|
|
|
|
public QuestNotifyCacheRequest(UserBase owner, string userGuid, RedisConnector redisConnector) : base(owner, redisConnector)
|
|
{
|
|
m_user_guid = userGuid;
|
|
}
|
|
|
|
|
|
|
|
protected override string onMakeKey()
|
|
{
|
|
return $"questnotify:{m_user_guid}";
|
|
}
|
|
|
|
|
|
|
|
public override string toBasicString()
|
|
{
|
|
return $"QuestNotifyCache: In:m_user_guid:{m_user_guid}";
|
|
}
|
|
|
|
private string makeFieldKey()
|
|
{
|
|
return $"{m_quest_id}:{m_quest_revision}";
|
|
}
|
|
|
|
private string makeFieldKey(UInt32 questId, UInt32 questRevision)
|
|
{
|
|
return $"{questId}:{questRevision}";
|
|
}
|
|
|
|
public async Task<Result> addQuestNotify()
|
|
{
|
|
var result = new Result();
|
|
var database = getDatabase();
|
|
QuestNotifyCache cache = new QuestNotifyCache(m_quest_id, m_quest_revision);
|
|
//일단 예외처리는 하지 않는다.
|
|
await database.HashSetAsync(onMakeKey(), makeFieldKey(), JsonConvert.SerializeObject(cache));
|
|
await database.KeyExpireAsync(onMakeKey(), TimeSpan.FromMilliseconds(Constant.QUEST_NOTIFY_CHECK_TIME));
|
|
return result;
|
|
}
|
|
|
|
public async Task<List<QuestNotifyCache>> getQuestNotifyAll()
|
|
{
|
|
var database = getDatabase();
|
|
|
|
List<QuestNotifyCache> notify_caches = new();
|
|
|
|
var hashes = await database.HashGetAllAsync(onMakeKey(), CommandFlags.PreferReplica);
|
|
|
|
foreach (var entry in hashes)
|
|
{
|
|
try
|
|
{
|
|
var value_string = entry.Value.ToString();
|
|
var notify_cache = JsonConvert.DeserializeObject<QuestNotifyCache>(value_string);
|
|
if (notify_cache == null)
|
|
{
|
|
string err_msg = $"Failed to get FriendCache from Redis !!! : : value_string:{value_string} - {getOwner().toBasicString()}";
|
|
Log.getLogger().error(err_msg);
|
|
continue;
|
|
}
|
|
notify_caches.Add(notify_cache);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.getLogger().error($"var value_string = entry.Value.ToString(); Failed. Exception message : {e.Message}");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return notify_caches;
|
|
|
|
}
|
|
|
|
public async Task<Result> deleteQuestNotify(UInt32 questId, UInt32 questRevision)
|
|
{
|
|
var result = new Result();
|
|
var database = getDatabase();
|
|
await database.HashDeleteAsync(onMakeKey(), makeFieldKey(questId, questRevision));
|
|
|
|
return result;
|
|
}
|
|
}
|