# Analytics Redis 초기화 스크립트

Write-Host "Analytics Redis 초기화 시작..." -ForegroundColor Cyan

# Redis 컨테이너 찾기
$redisContainer = docker ps --filter "ancestor=redis" --format "{{.Names}}" | Select-Object -First 1

if ($redisContainer) {
    Write-Host "Redis 컨테이너 발견: $redisContainer" -ForegroundColor Green

    # 멱등성 키 삭제
    Write-Host "멱등성 키 삭제 중..." -ForegroundColor Yellow
    docker exec $redisContainer redis-cli DEL processed_participants
    docker exec $redisContainer redis-cli DEL processed_events
    docker exec $redisContainer redis-cli DEL distribution_completed

    # 캐시 삭제
    Write-Host "Analytics 캐시 삭제 중..." -ForegroundColor Yellow
    docker exec $redisContainer redis-cli --scan --pattern "analytics:*" | ForEach-Object {
        docker exec $redisContainer redis-cli DEL $_
    }

    Write-Host "완료! 서버를 재시작해주세요." -ForegroundColor Green
} else {
    Write-Host "Redis 컨테이너를 찾을 수 없습니다." -ForegroundColor Red
    Write-Host "로컬 Redis를 시도합니다..." -ForegroundColor Yellow

    redis-cli DEL processed_participants
    redis-cli DEL processed_events
    redis-cli DEL distribution_completed

    Write-Host "완료! 서버를 재시작해주세요." -ForegroundColor Green
}
