초기커밋
This commit is contained in:
70
ServerBase/Redis/RedisConnector.cs
Normal file
70
ServerBase/Redis/RedisConnector.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
|
||||
using ServerCore;
|
||||
|
||||
|
||||
using MODULE_ID = System.UInt32;
|
||||
using SORT_ORDER_NO = System.Int32;
|
||||
|
||||
|
||||
namespace ServerBase;
|
||||
|
||||
public partial class RedisConnector : RedisConnectorBase, IModule, IInitializer
|
||||
{
|
||||
private readonly ModuleContext m_module_context;
|
||||
|
||||
public RedisConnector(ModuleContext context)
|
||||
: base(validateAndGetConnectionString(context))
|
||||
{
|
||||
m_module_context = context;
|
||||
}
|
||||
|
||||
private static string validateAndGetConnectionString(ModuleContext context)
|
||||
{
|
||||
if (context.getConfigParam() is not ConfigParam param)
|
||||
throw new InvalidCastException("IConfigParam must be of type RedisConnectorBase.ConfigParam !!!");
|
||||
|
||||
return param.ConnectionString;
|
||||
}
|
||||
|
||||
public async Task<Result> onInit()
|
||||
{
|
||||
var err_msg = string.Empty;
|
||||
var result = new Result();
|
||||
|
||||
var module_context = getModuleContext();
|
||||
var config_param = module_context.getConfigParam() as ConfigParam;
|
||||
NullReferenceCheckHelper.throwIfNull(config_param, () => $"config_param is null !!!");
|
||||
|
||||
var is_success = await tryConnectAsync();
|
||||
if (false == is_success)
|
||||
{
|
||||
err_msg = $"Failed to tryConnectAsync() !!! : {config_param.toBasicString()}";
|
||||
result.setFail(ServerErrorCode.RedisServerConnectFailed, err_msg);
|
||||
Log.getLogger().error(result.toBasicString());
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> startModule()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public async Task<Result> stopModule()
|
||||
{
|
||||
var result = new Result();
|
||||
return await Task.FromResult(result);
|
||||
}
|
||||
|
||||
public ModuleContext getModuleContext() => m_module_context;
|
||||
}
|
||||
Reference in New Issue
Block a user