Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ConcurrentModificationException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
Expand Down Expand Up @@ -53,7 +54,7 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.core.script.RedisScript;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import org.springframework.integration.support.locks.DistributedLock;
Expand Down Expand Up @@ -97,6 +98,7 @@
* @author Alex Peelman
* @author Youbin Wu
* @author Michal Domagala
* @author Severin Kistler
*
* @since 4.0
*
Expand Down Expand Up @@ -213,7 +215,7 @@ private void setupUnlockMessageListener(RedisConnectionFactory connectionFactory
"'unlockNotifyMessageListener' must not have been re-initialized.");
RedisLockRegistry.this.redisMessageListenerContainer = new RedisMessageListenerContainer();
RedisLockRegistry.this.unlockNotifyMessageListener = new RedisPubSubLock.RedisUnLockNotifyMessageListener();
final Topic topic = new ChannelTopic(this.unLockChannelKey);
final Topic topic = new PatternTopic(this.unLockChannelKey + ":*");
RedisMessageListenerContainer container = RedisLockRegistry.this.redisMessageListenerContainer;
RedisPubSubLock.RedisUnLockNotifyMessageListener listener = RedisLockRegistry.this.unlockNotifyMessageListener;
container.setConnectionFactory(connectionFactory);
Expand Down Expand Up @@ -667,7 +669,7 @@ private final class RedisPubSubLock extends RedisLock {
private static final String UNLINK_UNLOCK_SCRIPT = """
local lockClientId = redis.call('GET', KEYS[1])
if (lockClientId == ARGV[1] and redis.call('UNLINK', KEYS[1]) == 1) then
redis.call('PUBLISH', ARGV[2], KEYS[1])
redis.call('PUBLISH', KEYS[2], KEYS[1])
return true
end
return false
Expand All @@ -688,9 +690,10 @@ protected boolean tryRedisLockInner(long time, long expireAfter)

@Override
protected boolean removeLockKeyInnerUnlink() {
final String unLockChannelKey = RedisLockRegistry.this.unLockChannelKey + ":" + this.lockKey;
return Boolean.TRUE.equals(RedisLockRegistry.this.redisTemplate.execute(
UNLINK_UNLOCK_REDIS_SCRIPT, Collections.singletonList(this.lockKey),
RedisLockRegistry.this.clientId, RedisLockRegistry.this.unLockChannelKey));
UNLINK_UNLOCK_REDIS_SCRIPT, List.of(this.lockKey, unLockChannelKey),
RedisLockRegistry.this.clientId));
}

private boolean subscribeLock(long time, long expireAfter) throws ExecutionException, InterruptedException {
Expand Down