From 87b9c4a435daffa7eb4f1f455175442dc9fcf5a0 Mon Sep 17 00:00:00 2001 From: noear Date: Thu, 13 Apr 2023 12:35:50 +0800 Subject: [PATCH] =?UTF-8?q?sa-token-solon-plugin:=20=E5=8D=87=E7=BA=A7=20r?= =?UTF-8?q?edisx=20=E4=B8=BA=201.4.7=EF=BC=88set=20=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=20setex=EF=BC=89=EF=BC=8C=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=20dao=20=E9=80=82=E9=85=8D=E5=9C=A8=E5=B9=B6=E5=8F=91=E4=B8=8B?= =?UTF-8?q?=20getTimeout=20=E5=80=BC=E5=8F=AF=E8=83=BD=E4=B8=8E=20set=20?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA=E4=B8=8D=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++-- .../solon/dao/SaTokenDaoOfRedisBase64.java | 50 +++---------------- .../solon/dao/SaTokenDaoOfRedisJson.java | 50 +++---------------- 3 files changed, 19 insertions(+), 90 deletions(-) diff --git a/pom.xml b/pom.xml index f4954cd6..ad7711ab 100644 --- a/pom.xml +++ b/pom.xml @@ -22,10 +22,11 @@ sa-token-core sa-token-starter sa-token-plugin - - - - + sa-token-demo/sa-token-demo-sso-server-solon + sa-token-demo/sa-token-demo-sso1-client-solon + sa-token-demo/sa-token-demo-sso2-client-solon + sa-token-demo/sa-token-demo-sso3-client-solon + diff --git a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java index bca0e62f..2f6a4a26 100644 --- a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java +++ b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisBase64.java @@ -41,13 +41,7 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { */ @Override public void set(String key, String value, long timeout) { - if (timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - redisBucket.store(key, value, (int) SaTokenDao.NEVER_EXPIRE); - } else { + if (timeout > 0 || timeout == SaTokenDao.NEVER_EXPIRE) { redisBucket.store(key, value, (int) timeout); } } @@ -58,10 +52,6 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { @Override public void update(String key, String value) { long expire = getTimeout(key); - // -2 = 无此键 - if (expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } this.set(key, value, expire); } @@ -86,18 +76,9 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { */ @Override public void updateTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getTimeout(key); - if (expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.set(key, this.get(key), timeout); - } - return; + if (redisBucket.exists(key)) { + redisBucket.delay(key, (int) timeout); } - redisBucket.delay(key, (int) timeout); } @@ -114,13 +95,7 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { */ @Override public void setObject(String key, Object object, long timeout) { - if (timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - redisBucket.storeAndSerialize(key, object); - } else { + if (timeout > 0 || timeout == SaTokenDao.NEVER_EXPIRE) { redisBucket.storeAndSerialize(key, object, (int) timeout); } } @@ -131,10 +106,6 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { @Override public void updateObject(String key, Object object) { long expire = getObjectTimeout(key); - // -2 = 无此键 - if (expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } this.setObject(key, object, expire); } @@ -159,18 +130,9 @@ public class SaTokenDaoOfRedisBase64 implements SaTokenDao { */ @Override public void updateObjectTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getObjectTimeout(key); - if (expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.setObject(key, this.getObject(key), timeout); - } - return; + if (redisBucket.exists(key)) { + redisBucket.delay(key, (int) timeout); } - redisBucket.delay(key, (int) timeout); } diff --git a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisJson.java b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisJson.java index fdddbb03..2fba0461 100644 --- a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisJson.java +++ b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/dao/SaTokenDaoOfRedisJson.java @@ -57,13 +57,7 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { */ @Override public void set(String key, String value, long timeout) { - if (timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } - // 判断是否为永不过期 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - redisBucket.store(key, value, (int) SaTokenDao.NEVER_EXPIRE); - } else { + if (timeout > 0 || timeout == SaTokenDao.NEVER_EXPIRE) { redisBucket.store(key, value, (int) timeout); } } @@ -74,10 +68,6 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { @Override public void update(String key, String value) { long expire = getTimeout(key); - // -2 = 无此键 - if (expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } this.set(key, value, expire); } @@ -102,18 +92,9 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { */ @Override public void updateTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getTimeout(key); - if (expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.set(key, this.get(key), timeout); - } - return; + if (redisBucket.exists(key)) { + redisBucket.delay(key, (int) timeout); } - redisBucket.delay(key, (int) timeout); } @@ -130,12 +111,10 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { */ @Override public void setObject(String key, Object object, long timeout) { - if (timeout == 0 || timeout <= SaTokenDao.NOT_VALUE_EXPIRE) { - return; + if (timeout > 0 || timeout == SaTokenDao.NEVER_EXPIRE) { + String value = ONode.serialize(object); + set(key, value, timeout); } - - String value = ONode.serialize(object); - set(key, value, timeout); } /** @@ -144,10 +123,6 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { @Override public void updateObject(String key, Object object) { long expire = getObjectTimeout(key); - // -2 = 无此键 - if (expire == SaTokenDao.NOT_VALUE_EXPIRE) { - return; - } this.setObject(key, object, expire); } @@ -172,18 +147,9 @@ public class SaTokenDaoOfRedisJson implements SaTokenDao { */ @Override public void updateObjectTimeout(String key, long timeout) { - // 判断是否想要设置为永久 - if (timeout == SaTokenDao.NEVER_EXPIRE) { - long expire = getObjectTimeout(key); - if (expire == SaTokenDao.NEVER_EXPIRE) { - // 如果其已经被设置为永久,则不作任何处理 - } else { - // 如果尚未被设置为永久,那么再次set一次 - this.setObject(key, this.getObject(key), timeout); - } - return; + if (redisBucket.exists(key)) { + redisBucket.delay(key, (int) timeout); } - redisBucket.delay(key, (int) timeout); }