🐛 #3631 修复tryLock和unlock中针对Key的序列化方式不一致导致无法unlock的问题#3706
Merged
binarywang merged 1 commit intobinarywang:developfrom Sep 22, 2025
Merged
🐛 #3631 修复tryLock和unlock中针对Key的序列化方式不一致导致无法unlock的问题#3706binarywang merged 1 commit intobinarywang:developfrom
tryLock和unlock中针对Key的序列化方式不一致导致无法unlock的问题#3706binarywang merged 1 commit intobinarywang:developfrom
Conversation
There was a problem hiding this comment.
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
tryLockmethod 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; |
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.