diff --git a/jero-boot/jero-boot-base/jero-boot-base-tools/src/main/java/com/jero/common/modules/redis/writer/JeroRedisCacheWriter.java b/jero-boot/jero-boot-base/jero-boot-base-tools/src/main/java/com/jero/common/modules/redis/writer/JeroRedisCacheWriter.java index 9fb81d95..9499d85b 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-tools/src/main/java/com/jero/common/modules/redis/writer/JeroRedisCacheWriter.java +++ b/jero-boot/jero-boot-base/jero-boot-base-tools/src/main/java/com/jero/common/modules/redis/writer/JeroRedisCacheWriter.java @@ -25,6 +25,10 @@ import java.util.function.Function; @Slf4j public class JeroRedisCacheWriter implements RedisCacheWriter { + private static final String NAME_MUST_NOT_BE_NULL = "Name must not be null!"; + private static final String KEY_MUST_NOT_BE_NULL = "Key must not be null!"; + + private final RedisConnectionFactory connectionFactory; private final Duration sleepTime; @@ -39,9 +43,10 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { this.sleepTime = sleepTime; } + @Override public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl) { - Assert.notNull(name, "Name must not be null!"); - Assert.notNull(key, "Key must not be null!"); + Assert.notNull(name, NAME_MUST_NOT_BE_NULL); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "Value must not be null!"); this.execute(name, (connection) -> { if (shouldExpireWithin(ttl)) { @@ -54,19 +59,19 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { }); } + @Override public byte[] get(String name, byte[] key) { - Assert.notNull(name, "Name must not be null!"); - Assert.notNull(key, "Key must not be null!"); - return (byte[])this.execute(name, (connection) -> { - return connection.get(key); - }); + Assert.notNull(name, NAME_MUST_NOT_BE_NULL); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); + return this.execute(name, (connection) -> connection.get(key)); } + @Override public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) { - Assert.notNull(name, "Name must not be null!"); - Assert.notNull(key, "Key must not be null!"); + Assert.notNull(name, NAME_MUST_NOT_BE_NULL); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); Assert.notNull(value, "Value must not be null!"); - return (byte[])this.execute(name, (connection) -> { + return this.execute(name, (connection) -> { if (this.isLockingCacheWriter()) { this.doLock(name, connection); } @@ -81,8 +86,7 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { } if (!put) { - byte[] var11 = connection.get(key); - return var11; + return connection.get(key); } var7 = null; @@ -97,12 +101,13 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { }); } + @Override public void remove(String name, byte[] key) { - Assert.notNull(name, "Name must not be null!"); - Assert.notNull(key, "Key must not be null!"); + Assert.notNull(name, NAME_MUST_NOT_BE_NULL); + Assert.notNull(key, KEY_MUST_NOT_BE_NULL); String keyString = new String(key); log.info("redis remove key:" + keyString); - if(keyString!=null && keyString.endsWith("*")){ + if(keyString.endsWith("*")){ execute(name, connection -> { // 获取某个前缀所拥有的所有的键,某个前缀开头,后面肯定是* Set keys = connection.keys(key); @@ -113,14 +118,13 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { return delNum; }); }else{ - this.execute(name, (connection) -> { - return connection.del(new byte[][]{key}); - }); + this.execute(name, (connection) -> connection.del(new byte[][]{key})); } } + @Override public void clean(String name, byte[] pattern) { - Assert.notNull(name, "Name must not be null!"); + Assert.notNull(name, NAME_MUST_NOT_BE_NULL); Assert.notNull(pattern, "Pattern must not be null!"); this.execute(name, (connection) -> { boolean wasLocked = false; @@ -147,15 +151,11 @@ public class JeroRedisCacheWriter implements RedisCacheWriter { } void lock(String name) { - this.execute(name, (connection) -> { - return this.doLock(name, connection); - }); + this.execute(name, (connection) -> this.doLock(name, connection)); } void unlock(String name) { - this.executeLockFree((connection) -> { - this.doUnlock(name, connection); - }); + this.executeLockFree((connection) -> this.doUnlock(name, connection)); } private Boolean doLock(String name, RedisConnection connection) {