-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGarnetService.cs
39 lines (33 loc) · 1.11 KB
/
GarnetService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using CacheService.Configuration;
using Garnet;
namespace CacheService;
/// <summary>
/// A service for running a Garnet server.
/// </summary>
internal sealed partial class GarnetService(
ILogger<GarnetService> logger,
ISecretVault secretVault,
IConfigService cfgService) : BackgroundService
{
private readonly ILogger<GarnetService> _logger = logger;
/// <inheritdoc/>
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (!stoppingToken.IsCancellationRequested)
{
var options = await cfgService.GetServerOptions(secretVault);
LogServerInfo(options.Address, options.Port);
using var server = new GarnetServer(options);
server.Start();
await Task.Delay(Timeout.Infinite, stoppingToken);
}
}
/// <summary>
/// Method for logging basic server information.
/// </summary>
[LoggerMessage(
EventId = 0,
Level = LogLevel.Information,
Message = "Starting a Garnet server on {Host}:{Port}")]
public partial void LogServerInfo(string host, int port);
}