From 4228ac4570831426dbd2a805aee16c8e269819b9 Mon Sep 17 00:00:00 2001 From: Chopper Date: Thu, 2 Dec 2021 19:49:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?es=E6=97=A0=E6=95=88=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lili/controller/other/ElasticsearchController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java index 453d1efd..a3da87d4 100644 --- a/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java +++ b/manager-api/src/main/java/cn/lili/controller/other/ElasticsearchController.java @@ -1,6 +1,5 @@ package cn.lili.controller.other; -import cn.lili.cache.Cache; import cn.lili.common.enums.ResultUtil; import cn.lili.common.vo.ResultMessage; import cn.lili.modules.search.service.EsGoodsIndexService; @@ -27,9 +26,6 @@ public class ElasticsearchController { @Autowired private EsGoodsIndexService esGoodsIndexService; - @Autowired - private Cache cache; - @GetMapping public ResultMessage init() { esGoodsIndexService.init(); From 5e4973fae57b0c201326cce93e26202eedd31b10 Mon Sep 17 00:00:00 2001 From: Chopper Date: Fri, 3 Dec 2021 10:25:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/cache/util/RedisUtil.java | 250 ------------------ 1 file changed, 250 deletions(-) delete mode 100644 framework/src/main/java/cn/lili/cache/util/RedisUtil.java diff --git a/framework/src/main/java/cn/lili/cache/util/RedisUtil.java b/framework/src/main/java/cn/lili/cache/util/RedisUtil.java deleted file mode 100644 index 98516a63..00000000 --- a/framework/src/main/java/cn/lili/cache/util/RedisUtil.java +++ /dev/null @@ -1,250 +0,0 @@ -package cn.lili.cache.util; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.DefaultTypedTuple; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -/** - * Redis封装工具类 - * - * @author paulG - * @since 2020/11/7 - **/ -@Slf4j -@Component -public class RedisUtil { - @Autowired - private RedisTemplate redisTemplate; - - //=============================common============================ - - /** - * 指定缓存失效时间 - * - * @param key 键 - * @param time 时间(秒) - * @return 操作结果 - */ - public boolean expire(String key, long time) { - try { - if (time > 0) { - redisTemplate.expire(key, time, TimeUnit.SECONDS); - } - return true; - } catch (Exception e) { - log.error("指定缓存失效时间错误",e); - return false; - } - } - - - //============================String============================= - - /** - * 普通缓存获取 - * - * @param key 键 - * @return 值 - */ - public Object get(String key) { - return key == null ? null : redisTemplate.opsForValue().get(key); - } - - - /** - * 普通缓存获取 - * - * @param key 键 - * @return 值 - */ - public T get(String key, Class clazz) { - Object o = key == null ? null : redisTemplate.opsForValue().get(key); - return (T) o; - } - - /** - * 普通缓存放入 - * - * @param key 键 - * @param value 值 - * @return true成功 false失败 - */ - public boolean set(String key, Object value) { - try { - redisTemplate.opsForValue().set(key, value); - return true; - } catch (Exception e) { - log.error("缓存放入错误",e); - return false; - } - - } - - /** - * 普通缓存放入并设置时间 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 - * @return true成功 false 失败 - */ - public boolean set(String key, Object value, long time) { - try { - if (time > 0) { - redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); - } else { - set(key, value); - } - return true; - } catch (Exception e) { - log.error("普通缓存放入并设置时间错误",e); - return false; - } - } - - //================================Map================================= - - - /** - * 将数据放入set缓存 - * - * @param key 键 - * @param values 值 可以是多个 - * @return 成功个数 - */ - public long sSet(String key, Object... values) { - try { - return redisTemplate.opsForSet().add(key, values); - } catch (Exception e) { - log.error("将数据放入set缓存错误",e); - return 0; - } - } - - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return 操作结果 - */ - public boolean lSet(String key, Object value) { - try { - redisTemplate.opsForList().rightPush(key, value); - return true; - } catch (Exception e) { - log.error("将list放入缓存错误",e); - return false; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return 操作结果 - */ - public boolean lSet(String key, Object value, long time) { - try { - redisTemplate.opsForList().rightPush(key, value); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error("将list放入缓存错误",e); - return false; - } - } - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @return 操作结果 - */ - public boolean lSet(String key, List value) { - try { - redisTemplate.opsForList().rightPushAll(key, value); - return true; - } catch (Exception e) { - log.error("将list放入缓存错误",e); - return false; - } - } - - - /** - * 将list放入缓存 - * - * @param key 键 - * @param value 值 - * @param time 时间(秒) - * @return 操作结果 - */ - public boolean lSet(String key, List value, long time) { - try { - redisTemplate.opsForList().rightPushAll(key, value); - if (time > 0) { - expire(key, time); - } - return true; - } catch (Exception e) { - log.error("将list放入缓存错误",e); - return false; - } - } - - - //===============================ZSet================================= - - /** - * 向Zset里添加成员 - * - * @param key 键 - * @param score 分数 - * @param value 值 - * @return 操作结果 - */ - public boolean zadd(String key, long score, String value) { - return redisTemplate.opsForZSet().add(key, value, score); - - } - - - /** - * 获取 某key 下 某一分值区间的队列 - * - * @param key 键 - * @param from 起始位置 - * @param to 结束为止 - * @return 符合条件的结果集 - */ - public Set zrangeByScoreWithScores(String key, int from, long to) { - Set set = redisTemplate.opsForZSet().rangeByScoreWithScores(key, from, to); - return set; - } - - /** - * 移除 Zset队列值 - * - * @param key 键 - * @param value 值集合 - * @return 移除数量 - */ - public Long zremove(String key, String... value) { - return redisTemplate.opsForZSet().remove(key, value); - - } - -}