-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |