feat: add channel create responder and redis webhook cache

This commit is contained in:
sam 2024-08-16 22:28:05 +02:00
parent 99c1587e7b
commit e86b37ce2a
11 changed files with 201 additions and 10 deletions

View file

@ -0,0 +1,24 @@
using System.Text.Json;
using Humanizer;
using StackExchange.Redis;
namespace Catalogger.Backend.Database.Redis;
public class RedisService(Config config)
{
private readonly ConnectionMultiplexer _multiplexer = ConnectionMultiplexer.Connect(config.Database.Redis!);
public IDatabase GetDatabase(int db = -1) => _multiplexer.GetDatabase(db);
public async Task SetAsync<T>(string key, T value, TimeSpan? expiry = null)
{
var json = JsonSerializer.Serialize(value);
await GetDatabase().StringSetAsync(key, json, expiry);
}
public async Task<T?> GetAsync<T>(string key)
{
var value = await GetDatabase().StringGetAsync(key);
return value.IsNull ? default : JsonSerializer.Deserialize<T>(value!);
}
}