package com.boying.util;
|
|
import com.alibaba.fastjson.JSON;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import org.apache.ibatis.jdbc.Null;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.io.IOException;
|
|
/**
|
* @author kdq
|
* @version 1.0.0
|
* @ClassName RedisJsonUtil.java
|
* @Description TODO
|
* @createTime 2024年03月18日 15:20:00
|
*/
|
@Component
|
public class RedisJsonUtil {
|
|
private static StringRedisTemplate stringRedisTemplate;
|
|
public static <T> void set(String key, T value) throws IOException {
|
String jsonValue = JSON.toJSONString(value);
|
stringRedisTemplate.opsForValue().set(key, jsonValue);
|
}
|
|
public static <T> T get(String key, Class<T> type) throws IOException {
|
String jsonValue = stringRedisTemplate.opsForValue().get(key);
|
return jsonValue == null ? null : JSON.parseObject(jsonValue, type);
|
}
|
public static void del(String key) {
|
stringRedisTemplate.delete(key);
|
}
|
|
}
|