package com.kt.event.eventservice.presentation.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.time.Duration;

/**
 * Redis 연결 테스트 컨트롤러
 */
@Slf4j
@RestController
@RequestMapping("/redis-test")
@RequiredArgsConstructor
public class RedisTestController {

    private final StringRedisTemplate redisTemplate;

    @GetMapping("/ping")
    public String ping() {
        try {
            String key = "test:ping";
            String value = "pong:" + System.currentTimeMillis();

            log.info("Redis test - setting key: {}, value: {}", key, value);
            redisTemplate.opsForValue().set(key, value, Duration.ofSeconds(60));

            String result = redisTemplate.opsForValue().get(key);
            log.info("Redis test - retrieved value: {}", result);

            return "Redis OK - " + result;
        } catch (Exception e) {
            log.error("Redis connection failed", e);
            return "Redis FAILED - " + e.getMessage();
        }
    }
}
