feat: add channel create responder and redis webhook cache
This commit is contained in:
parent
99c1587e7b
commit
e86b37ce2a
11 changed files with 201 additions and 10 deletions
24
Catalogger.Backend/Database/Redis/RedisService.cs
Normal file
24
Catalogger.Backend/Database/Redis/RedisService.cs
Normal 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!);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue