Add command to flush redis database

This commit is contained in:
jvyden 2022-06-10 02:42:24 -04:00
commit 02abb7bcab
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 35 additions and 2 deletions

View file

@ -0,0 +1,20 @@
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.StorableLists;
namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.Commands;
public class FlushRedisCommand : ICommand
{
public string Name() => "Flush Redis";
public string[] Aliases() => new[] {
"flush", "flush-redis",
};
public string Arguments() => "";
public int RequiredArgs() => 0;
public async Task Run(string[] args, Logger logger)
{
await RedisDatabase.FlushAll();
}
}

View file

@ -39,8 +39,7 @@ public static class RedisDatabase
return;
}
await connection.RecreateIndexAsync(typeof(Room));
await connection.RecreateIndexAsync(typeof(UserFriendData));
await createIndexes(connection);
}
catch(Exception e)
{
@ -52,6 +51,20 @@ public static class RedisDatabase
Logger.Success("Initialized Redis.", LogArea.Redis);
}
public static async Task FlushAll()
{
IRedisConnection connection = getConnection();
await connection.ExecuteAsync("FLUSHALL");
await createIndexes(connection);
}
private static async Task createIndexes(IRedisConnection connection)
{
await connection.RecreateIndexAsync(typeof(Room));
await connection.RecreateIndexAsync(typeof(UserFriendData));
}
private static IRedisConnection getConnection()
{
Logger.Debug("Getting a Redis connection", LogArea.Redis);