Skip to content

extract cluster hash tag on encoded bytes in getSlot(String) - #4686

Closed
insaf021 wants to merge 1 commit into
redis:masterfrom
insaf021:cluster-slot-encoded-hashtag
Closed

extract cluster hash tag on encoded bytes in getSlot(String)#4686
insaf021 wants to merge 1 commit into
redis:masterfrom
insaf021:cluster-slot-encoded-hashtag

Conversation

@insaf021

@insaf021 insaf021 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor
getSlot("<GBK 81 7B 41 81 7D>")                     -> slot 14821
getSlot(SafeEncoder.encode("<GBK 81 7B 41 81 7D>")) -> slot 16212   (== server keyHashSlot)

getSlot(String) locates the {hash tag} by scanning for the { and } characters and only encodes to bytes afterwards. The byte[] overload and the server's keyHashSlot() scan for 0x7B/0x7D in the encoded bytes. Under a DBCS SafeEncoder.DEFAULT_CHARSET (GBK, Shift_JIS, Big5) a trail byte can be 0x7B/0x7D while the char is not a brace, so the String path picks a different tag (or none) and routes to a slot the server does not own. It also disagrees with the binary API for the same logical key, which reaches routing through CommandArguments.getKeyHashSlots().

Delegating to the byte overload moves brace scanning onto the wire bytes. No-op under UTF-8 since no multibyte sequence contains 0x7B/0x7D; the added regression covers both the GBK mismatch and the UTF-8 parity.

Companion issue #4685.


Note

Medium Risk
Changes core cluster routing for all String keys; fix is targeted and covered by regression tests, but mis-routing before was silent and wrong-slot bugs are operationally serious.

Overview
Fixes wrong Redis Cluster slot routing when SafeEncoder.DEFAULT_CHARSET is a DBCS encoding (GBK, Shift_JIS, Big5). getSlot(String) no longer finds {/} on the Java String via JedisClusterHashTag; it encodes the key first and delegates to getSlot(byte[]), matching Redis keyHashSlot() and the binary API.

Under DBCS, trail bytes can be 0x7B/0x7D without being brace characters, so the old String scan could pick a different hash tag (or none) and send commands to the wrong node. UTF-8 behavior is unchanged.

Adds testHashtagGetSlotMatchesEncodedBytesUnderDbcsCharset to assert getSlot(String) equals getSlot(encoded bytes) for a GBK key and for UTF-8.

Reviewed by Cursor Bugbot for commit 79dd2cf. Bugbot is set up for automated code reviews on this repo. Configure here.

@ggivo

ggivo commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Before reviewing the PR related issue need to be triaged/accepted by the team

@ggivo ggivo closed this Aug 17, 2026
@ggivo

ggivo commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Closing as per the comment is related issue

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.

2 participants