Skip to content

Conversation

imyzt
Copy link
Contributor

@imyzt imyzt commented Sep 18, 2025

No description provided.

@binarywang binarywang requested a review from Copilot September 22, 2025 16:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes a bug where inconsistent key serialization between tryLock and unlock methods in RedisTemplateSimpleDistributedLock prevented proper lock release. The fix ensures both methods use the same Redis template serializers instead of manual UTF-8 encoding.

  • Updates tryLock method to use RedisTemplate's key and value serializers instead of hardcoded UTF-8 encoding
  • Adds comprehensive test with custom key serializer to reproduce and validate the fix
  • Enables the previously disabled test suite to verify the bug fix

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
RedisTemplateSimpleDistributedLock.java Fixed key serialization inconsistency by using RedisTemplate serializers
RedisTemplateSimpleDistributedLockTest.java Added test with custom key serializer and enabled test suite

Comment on lines +50 to +54
String key = super.deserialize(bytes);
if (key.startsWith(KEY_PREFIX)) {
return key.substring(KEY_PREFIX.length());
}
return key;
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deserialize method doesn't handle null values properly. If super.deserialize(bytes) returns null, calling startsWith() will throw a NullPointerException. Add a null check before the prefix validation.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RedisTemplateSimpleDistributedLock 在trylock和unlock 中针对Key的序列化方式不一致导致无法unlock的问题。
2 participants