【fix sonar】JeroRedisCacheWriter文件
This commit is contained in:
+25
-25
@@ -25,6 +25,10 @@ import java.util.function.Function;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class JeroRedisCacheWriter implements RedisCacheWriter {
|
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 RedisConnectionFactory connectionFactory;
|
||||||
private final Duration sleepTime;
|
private final Duration sleepTime;
|
||||||
|
|
||||||
@@ -39,9 +43,10 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
this.sleepTime = sleepTime;
|
this.sleepTime = sleepTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
|
public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
|
||||||
Assert.notNull(name, "Name must not be null!");
|
Assert.notNull(name, NAME_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(key, "Key must not be null!");
|
Assert.notNull(key, KEY_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(value, "Value must not be null!");
|
Assert.notNull(value, "Value must not be null!");
|
||||||
this.execute(name, (connection) -> {
|
this.execute(name, (connection) -> {
|
||||||
if (shouldExpireWithin(ttl)) {
|
if (shouldExpireWithin(ttl)) {
|
||||||
@@ -54,19 +59,19 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] get(String name, byte[] key) {
|
public byte[] get(String name, byte[] key) {
|
||||||
Assert.notNull(name, "Name must not be null!");
|
Assert.notNull(name, NAME_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(key, "Key must not be null!");
|
Assert.notNull(key, KEY_MUST_NOT_BE_NULL);
|
||||||
return (byte[])this.execute(name, (connection) -> {
|
return this.execute(name, (connection) -> connection.get(key));
|
||||||
return connection.get(key);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
|
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
|
||||||
Assert.notNull(name, "Name must not be null!");
|
Assert.notNull(name, NAME_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(key, "Key must not be null!");
|
Assert.notNull(key, KEY_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(value, "Value 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()) {
|
if (this.isLockingCacheWriter()) {
|
||||||
this.doLock(name, connection);
|
this.doLock(name, connection);
|
||||||
}
|
}
|
||||||
@@ -81,8 +86,7 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!put) {
|
if (!put) {
|
||||||
byte[] var11 = connection.get(key);
|
return connection.get(key);
|
||||||
return var11;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var7 = null;
|
var7 = null;
|
||||||
@@ -97,12 +101,13 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void remove(String name, byte[] key) {
|
public void remove(String name, byte[] key) {
|
||||||
Assert.notNull(name, "Name must not be null!");
|
Assert.notNull(name, NAME_MUST_NOT_BE_NULL);
|
||||||
Assert.notNull(key, "Key must not be null!");
|
Assert.notNull(key, KEY_MUST_NOT_BE_NULL);
|
||||||
String keyString = new String(key);
|
String keyString = new String(key);
|
||||||
log.info("redis remove key:" + keyString);
|
log.info("redis remove key:" + keyString);
|
||||||
if(keyString!=null && keyString.endsWith("*")){
|
if(keyString.endsWith("*")){
|
||||||
execute(name, connection -> {
|
execute(name, connection -> {
|
||||||
// 获取某个前缀所拥有的所有的键,某个前缀开头,后面肯定是*
|
// 获取某个前缀所拥有的所有的键,某个前缀开头,后面肯定是*
|
||||||
Set<byte[]> keys = connection.keys(key);
|
Set<byte[]> keys = connection.keys(key);
|
||||||
@@ -113,14 +118,13 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
return delNum;
|
return delNum;
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
this.execute(name, (connection) -> {
|
this.execute(name, (connection) -> connection.del(new byte[][]{key}));
|
||||||
return connection.del(new byte[][]{key});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void clean(String name, byte[] pattern) {
|
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!");
|
Assert.notNull(pattern, "Pattern must not be null!");
|
||||||
this.execute(name, (connection) -> {
|
this.execute(name, (connection) -> {
|
||||||
boolean wasLocked = false;
|
boolean wasLocked = false;
|
||||||
@@ -147,15 +151,11 @@ public class JeroRedisCacheWriter implements RedisCacheWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void lock(String name) {
|
void lock(String name) {
|
||||||
this.execute(name, (connection) -> {
|
this.execute(name, (connection) -> this.doLock(name, connection));
|
||||||
return this.doLock(name, connection);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void unlock(String name) {
|
void unlock(String name) {
|
||||||
this.executeLockFree((connection) -> {
|
this.executeLockFree((connection) -> this.doUnlock(name, connection));
|
||||||
this.doUnlock(name, connection);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean doLock(String name, RedisConnection connection) {
|
private Boolean doLock(String name, RedisConnection connection) {
|
||||||
|
|||||||
Reference in New Issue
Block a user