From 2d752894cdfc6f09f967f3ab9601b8813decec65 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 14 Dec 2021 19:50:49 -0500 Subject: [PATCH] Fix UNLINK/DEL logic in the RedisLockRegistry See review: https://github.com/spring-projects/spring-integration/pull/3691#issuecomment-994124360 --- .../redis/util/RedisLockRegistry.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java index 2208a90579..4f408d3c59 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java @@ -438,27 +438,29 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl } private void removeLockKey() { - try { - if (RedisLockRegistry.this.unlinkAvailable) { + if (RedisLockRegistry.this.unlinkAvailable) { + try { RedisLockRegistry.this.redisTemplate.execute( RedisLockRegistry.this.unLinkUnLockScript, Collections.singletonList(this.lockKey), RedisLockRegistry.this.unLockChannelKey); + return; + } + catch (Exception ex) { + RedisLockRegistry.this.unlinkAvailable = false; + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("The UNLINK command has failed (not supported on the Redis server?); " + + "falling back to the regular DELETE command", ex); + } + else { + LOGGER.warn("The UNLINK command has failed (not supported on the Redis server?); " + + "falling back to the regular DELETE command: " + ex.getMessage()); + } } } - catch (Exception ex) { - RedisLockRegistry.this.unlinkAvailable = false; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("The UNLINK command has failed (not supported on the Redis server?); " + - "falling back to the regular DELETE command", ex); - } - else { - LOGGER.warn("The UNLINK command has failed (not supported on the Redis server?); " + - "falling back to the regular DELETE command: " + ex.getMessage()); - } - RedisLockRegistry.this.redisTemplate.execute( - RedisLockRegistry.this.deleteUnLockScript, Collections.singletonList(this.lockKey), - RedisLockRegistry.this.unLockChannelKey); - } + + RedisLockRegistry.this.redisTemplate.execute( + RedisLockRegistry.this.deleteUnLockScript, Collections.singletonList(this.lockKey), + RedisLockRegistry.this.unLockChannelKey); } @Override