41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Garnet;
|
|
|
|
namespace SchemaEditor.Services;
|
|
|
|
public class GarnetHost : IHostedService, IDisposable
|
|
{
|
|
private GarnetServer? _server;
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
var serverArgs = new string[] { "--port", "3187" }; // Changed to 3187
|
|
_server = new GarnetServer(serverArgs);
|
|
_server.Start();
|
|
Console.WriteLine("[GarnetHost] Server started on port 3187");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"[GarnetHost] Failed to start: {ex.Message}");
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_server?.Dispose();
|
|
Console.WriteLine("[GarnetHost] Server stopped");
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_server?.Dispose();
|
|
}
|
|
}
|