Skip to content

Commit

Permalink
feat: RedisUtil 추가
Browse files Browse the repository at this point in the history
related to: #11
  • Loading branch information
heejjinkim committed Sep 7, 2024
1 parent e2c84ca commit 6693930
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/com/_119/wepro/global/util/RedisUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com._119.wepro.global.util;

import java.time.Duration;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

@RequiredArgsConstructor
@Component
public class RedisUtil {

private final RedisTemplate<String, String> redisTemplate;

public String getData(String key) {
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
return valueOperations.get(key);
}

public void setData(String key, String value) {
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
valueOperations.set(key, value);
}

public void setDataExpire(String key, String value, long duration) {
ValueOperations<String, String> valueOperations = redisTemplate.opsForValue();
valueOperations.set(key, value, Duration.ofMillis(duration));
}

public void deleteData(String key) {
redisTemplate.delete(key);
}

public void expireValues(String key, int timeout) {
redisTemplate.expire(key, timeout, TimeUnit.MILLISECONDS);
}

public boolean existsData(String key) {
return redisTemplate.hasKey(key);
}
}

0 comments on commit 6693930

Please sign in to comment.