feat(bot): add Redis cache
This commit is contained in:
@@ -20,6 +20,7 @@ public class BotConfig
|
||||
|
||||
public string? GatewayQueueUrl { get; set; }
|
||||
public bool UseRedisRatelimiter { get; set; } = false;
|
||||
public bool UseRedisCache { get; set; } = false;
|
||||
|
||||
public string? RedisGatewayUrl { get; set; }
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using Autofac;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
using Myriad.Cache;
|
||||
using Myriad.Gateway;
|
||||
using Myriad.Types;
|
||||
using Myriad.Rest;
|
||||
@@ -51,6 +52,10 @@ public class Init
|
||||
if (config.UseRedisRatelimiter)
|
||||
await redis.InitAsync(coreConfig);
|
||||
|
||||
var cache = services.Resolve<IDiscordCache>();
|
||||
if (cache is RedisDiscordCache)
|
||||
await (cache as RedisDiscordCache).InitAsync(coreConfig.RedisAddr, config.ClientId!.Value);
|
||||
|
||||
if (config.Cluster == null)
|
||||
{
|
||||
// "Connect to the database" (ie. set off database migrations and ensure state)
|
||||
|
||||
@@ -44,7 +44,13 @@ public class BotModule: Module
|
||||
}).AsSelf().SingleInstance();
|
||||
builder.RegisterType<Cluster>().AsSelf().SingleInstance();
|
||||
builder.RegisterType<RedisGatewayService>().AsSelf().SingleInstance();
|
||||
builder.Register(c => { return new MemoryDiscordCache(); }).AsSelf().As<IDiscordCache>().SingleInstance();
|
||||
builder.Register<IDiscordCache>(c => {
|
||||
var botConfig = c.Resolve<BotConfig>();
|
||||
|
||||
if (botConfig.UseRedisCache)
|
||||
return new RedisDiscordCache(c.Resolve<ILogger>());
|
||||
return new MemoryDiscordCache();
|
||||
}).AsSelf().SingleInstance();
|
||||
builder.RegisterType<PrivateChannelService>().AsSelf().SingleInstance();
|
||||
|
||||
builder.Register(c =>
|
||||
|
||||
@@ -1520,6 +1520,8 @@
|
||||
"myriad": {
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"Google.Protobuf": "3.13.0",
|
||||
"Grpc.Net.ClientFactory": "2.32.0",
|
||||
"Polly": "7.2.1",
|
||||
"Polly.Contrib.WaitAndRetry": "1.1.1",
|
||||
"Serilog": "2.10.0",
|
||||
|
||||
Reference in New Issue
Block a user