From f8419592ff96d01e29a37b626cf1e48e7e50a9b6 Mon Sep 17 00:00:00 2001
From: Mamba <928477320@qq.com>
Date: Sun, 29 Sep 2019 15:27:17 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0redis=E5=B7=A5=E5=85=B7?=
=?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=AE=8C=E6=88=90100%=EF=BC=8C=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=E5=B7=A5=E5=85=B7?=
=?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=AE=8C=E6=88=9050%?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dev-common/pom.xml | 16 +
.../java/com/dev/common/utils/RedisUtils.java | 539 ++++++++++++++++++
.../com/dev/common/utils/SendMailUtils.java | 115 ++++
dev-framework/pom.xml | 6 +
.../com/dev/framework/config/RedisConfig.java | 56 ++
.../src/main/resources/application-dev.yml | 35 +-
.../src/main/resources/application-prod.yml | 157 +++--
.../main/resources/static/fly/mods/index.js | 9 +-
pom.xml | 9 +
9 files changed, 871 insertions(+), 71 deletions(-)
create mode 100644 dev-common/src/main/java/com/dev/common/utils/RedisUtils.java
create mode 100644 dev-common/src/main/java/com/dev/common/utils/SendMailUtils.java
create mode 100644 dev-framework/src/main/java/com/dev/framework/config/RedisConfig.java
diff --git a/dev-common/pom.xml b/dev-common/pom.xml
index f39fbd7..28f425a 100644
--- a/dev-common/pom.xml
+++ b/dev-common/pom.xml
@@ -110,6 +110,22 @@
org.springframework.data
spring-data-elasticsearch
+
+
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+ org.apache.commons
+ commons-pool2
+
\ No newline at end of file
diff --git a/dev-common/src/main/java/com/dev/common/utils/RedisUtils.java b/dev-common/src/main/java/com/dev/common/utils/RedisUtils.java
new file mode 100644
index 0000000..278bf79
--- /dev/null
+++ b/dev-common/src/main/java/com/dev/common/utils/RedisUtils.java
@@ -0,0 +1,539 @@
+package com.dev.common.utils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @Classname RedisUtil
+ * @Description redis工具类
+ * @Date 2019/9/24 18:08
+ * @Created by SSL
+ */
+@Component
+public class RedisUtils {
+ @Autowired
+ private static RedisTemplate redisTemplate;
+
+ public RedisUtils(RedisTemplate redisTemplate) {
+ this.redisTemplate = redisTemplate;
+ }
+
+
+ /**
+ * 指定缓存失效时间
+ * @param key 键
+ * @param time 时间(秒)
+ * @return
+ */
+ public static boolean expire(String key,long time){
+ try {
+ if(time>0){
+ redisTemplate.expire(key, time, TimeUnit.SECONDS);
+ }
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 根据key 获取过期时间
+ * @param key 键 不能为null
+ * @return 时间(秒) 返回0代表为永久有效
+ */
+ public static long getExpire(String key){
+ return redisTemplate.getExpire(key,TimeUnit.SECONDS);
+ }
+
+ /**
+ * 判断key是否存在
+ * @param key 键
+ * @return true 存在 false不存在
+ */
+ public static boolean hasKey(String key){
+ try {
+ return redisTemplate.hasKey(key);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 删除缓存
+ * @param key 可以传一个值 或多个
+ */
+ @SuppressWarnings("unchecked")
+ public static void del(String ... key){
+ if(key!=null&&key.length>0){
+ if(key.length==1){
+ redisTemplate.delete(key[0]);
+ }else{
+ redisTemplate.delete(CollectionUtils.arrayToList(key));
+ }
+ }
+ }
+
+ //============================String=============================
+ /**
+ * 普通缓存获取
+ * @param key 键
+ * @return 值
+ */
+ public static Object get(String key){
+ return key==null?null:redisTemplate.opsForValue().get(key);
+ }
+
+ /**
+ * 普通缓存放入
+ * @param key 键
+ * @param value 值
+ * @return true成功 false失败
+ */
+ public static boolean set(String key,Object value) {
+ try {
+ redisTemplate.opsForValue().set(key, value);
+ return true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 普通缓存放入并设置时间
+ * @param key 键
+ * @param value 值
+ * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
+ * @return true成功 false 失败
+ */
+ public static 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) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+ /**
+ * 递增
+ * @param key 键
+ * @param delta 要增加几(大于0)
+ * @return
+ */
+ public static long incr(String key, long delta){
+ if(delta<0){
+ throw new RuntimeException("递增因子必须大于0");
+ }
+ return redisTemplate.opsForValue().increment(key, delta);
+ }
+
+ /**
+ * 递减
+ * @param key 键
+ * @param delta 要减少几(小于0)
+ * @return
+ */
+ public static long decr(String key, long delta){
+ if(delta<0){
+ throw new RuntimeException("递减因子必须大于0");
+ }
+ return redisTemplate.opsForValue().increment(key, -delta);
+ }
+
+ //================================Map=================================
+ /**
+ * HashGet
+ * @param key 键 不能为null
+ * @param item 项 不能为null
+ * @return 值
+ */
+ public static Object hget(String key,String item){
+ return redisTemplate.opsForHash().get(key, item);
+ }
+
+ /**
+ * 获取hashKey对应的所有键值
+ * @param key 键
+ * @return 对应的多个键值
+ */
+ public static Map