Skip to content

Commit eaac0ed

Browse files
committed
add the lockKey to the unlockChannelKey to control cluster slot hashing
As a consequence, change the ChannelTopic to a PatternTopic to keep receiving subscription events for PubSub lock Signed-off-by: Severin Kistler <[email protected]>
1 parent 9f86108 commit eaac0ed

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-integration-redis/src/main/java/org/springframework/integration/redis/util/RedisLockRegistry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import org.springframework.data.redis.core.StringRedisTemplate;
5454
import org.springframework.data.redis.core.script.DefaultRedisScript;
5555
import org.springframework.data.redis.core.script.RedisScript;
56-
import org.springframework.data.redis.listener.ChannelTopic;
56+
import org.springframework.data.redis.listener.PatternTopic;
5757
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
5858
import org.springframework.data.redis.listener.Topic;
5959
import org.springframework.integration.support.locks.DistributedLock;
@@ -97,6 +97,7 @@
9797
* @author Alex Peelman
9898
* @author Youbin Wu
9999
* @author Michal Domagala
100+
* @author Severin Kistler
100101
*
101102
* @since 4.0
102103
*
@@ -213,7 +214,7 @@ private void setupUnlockMessageListener(RedisConnectionFactory connectionFactory
213214
"'unlockNotifyMessageListener' must not have been re-initialized.");
214215
RedisLockRegistry.this.redisMessageListenerContainer = new RedisMessageListenerContainer();
215216
RedisLockRegistry.this.unlockNotifyMessageListener = new RedisPubSubLock.RedisUnLockNotifyMessageListener();
216-
final Topic topic = new ChannelTopic(this.unLockChannelKey);
217+
final Topic topic = new PatternTopic(this.unLockChannelKey + ":*");
217218
RedisMessageListenerContainer container = RedisLockRegistry.this.redisMessageListenerContainer;
218219
RedisPubSubLock.RedisUnLockNotifyMessageListener listener = RedisLockRegistry.this.unlockNotifyMessageListener;
219220
container.setConnectionFactory(connectionFactory);
@@ -690,7 +691,7 @@ protected boolean tryRedisLockInner(long time, long expireAfter)
690691
protected boolean removeLockKeyInnerUnlink() {
691692
return Boolean.TRUE.equals(RedisLockRegistry.this.redisTemplate.execute(
692693
UNLINK_UNLOCK_REDIS_SCRIPT, Collections.singletonList(this.lockKey),
693-
RedisLockRegistry.this.clientId, RedisLockRegistry.this.unLockChannelKey));
694+
RedisLockRegistry.this.clientId, RedisLockRegistry.this.unLockChannelKey + ":" + this.lockKey));
694695
}
695696

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

0 commit comments

Comments
 (0)