mirror of
https://github.com/alex289/CleanArchitecture.git
synced 2025-08-23 11:48:37 +00:00
feat: Reset redis keys too
This commit is contained in:
parent
4a8c102d00
commit
2d415d3f55
@ -98,8 +98,11 @@ public sealed class CleanArchitectureWebApplicationFactory : WebApplicationFacto
|
|||||||
|
|
||||||
public async Task RespawnDatabaseAsync()
|
public async Task RespawnDatabaseAsync()
|
||||||
{
|
{
|
||||||
var accessor = DatabaseAccessor.GetOrCreateAsync(_instanceDatabaseName);
|
var dbAccessor = DatabaseAccessor.GetOrCreateAsync(_instanceDatabaseName);
|
||||||
await accessor.RespawnDatabaseAsync();
|
await dbAccessor.RespawnDatabaseAsync();
|
||||||
|
|
||||||
|
var redisAccessor = RedisAccessor.GetOrCreateAsync();
|
||||||
|
redisAccessor.ResetRedis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async ValueTask DisposeAsync()
|
public override async ValueTask DisposeAsync()
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Caching.Distributed;
|
using Microsoft.Extensions.Caching.Distributed;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using StackExchange.Redis;
|
||||||
using Testcontainers.Redis;
|
using Testcontainers.Redis;
|
||||||
|
|
||||||
namespace CleanArchitecture.IntegrationTests.Infrastructure;
|
namespace CleanArchitecture.IntegrationTests.Infrastructure;
|
||||||
@ -49,6 +49,26 @@ public sealed class RedisAccessor
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetRedis()
|
||||||
|
{
|
||||||
|
var redis = ConnectionMultiplexer.Connect(GetConnectionString());
|
||||||
|
|
||||||
|
var db = redis.GetDatabase();
|
||||||
|
|
||||||
|
var endpoints = redis.GetEndPoints();
|
||||||
|
foreach (var endpoint in endpoints)
|
||||||
|
{
|
||||||
|
var server = redis.GetServer(endpoint);
|
||||||
|
var keys = server.Keys();
|
||||||
|
foreach (var key in keys)
|
||||||
|
{
|
||||||
|
db.KeyDelete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redis.Close();
|
||||||
|
}
|
||||||
|
|
||||||
public static RedisAccessor GetOrCreateAsync()
|
public static RedisAccessor GetOrCreateAsync()
|
||||||
{
|
{
|
||||||
return s_accessors.GetOrAdd("redis", _ => new RedisAccessor());
|
return s_accessors.GetOrAdd("redis", _ => new RedisAccessor());
|
||||||
|
Loading…
Reference in New Issue
Block a user