package cn.iocoder.yudao.module.tkdata.job;

import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

/*
 * @author: ziin
 * @date: 2025/6/13 18:54
 */
@Component
@Slf4j
public class CleanTKAccountCache implements JobHandler {

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public String execute(String param) throws Exception {

        // 1. 获取所有匹配的 key（注意：keys 命令在生产环境可能阻塞 Redis，慎用！）
        Set<String> keys = redisTemplate.keys("tkaccount:" + "*");

        // 2. 如果找到 key，则批量删除
        if (keys != null && !keys.isEmpty()) {
             redisTemplate.delete(keys);
        }
        Boolean tkAccount = redisTemplate.delete("tkaccount:*");
        return String.format("清除缓存账号数量: %s", keys.size());
    }
}
