package com.css.simulation.resource.scheduler.infra.db.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Collection;
import java.util.Set;

@Slf4j
public class RedisUtil {


    public static void deleteByKeyCollection(StringRedisTemplate stringRedisTemplate, Collection<String> keyCollection) {
        stringRedisTemplate.delete(keyCollection);
    }

    public static void deleteByPrefix(StringRedisTemplate stringRedisTemplate, String prefix) {
        Set<String> keySetByPrefix = getKeySetByPrefix(stringRedisTemplate, prefix);
        deleteByKeyCollection(stringRedisTemplate, keySetByPrefix);
    }

    public static String getStringByKey(StringRedisTemplate stringRedisTemplate, String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    public static Set<String> getKeySetByPrefix(StringRedisTemplate stringRedisTemplate, String prefix) {
        return stringRedisTemplate.keys(prefix + "*");
    }




}
