Repository navigation
Expose HashSlot(RedisChannel) on IConnectionMultiplexer - #3366
Open
aradalvand wants to merge 1 commit into
Open
aradalvand wants to merge 1 commit into
aradalvand wants to merge 1 commit into
Conversation
There was no public way to ask which hash slot a channel is routed by. The
usual workaround, hashing the channel's name as a key, ignores
ConfigurationOptions.ChannelPrefix, and the key-based routing of single-key
keyspace channels. This exposes the existing internal
ServerSelectionStrategy.HashSlot(in RedisChannel), which accounts for both.
Strings and byte arrays convert implicitly to both RedisKey and RedisChannel,
so the existing HashSlot(RedisKey) gets [OverloadResolutionPriority(1)] to
keep calls like HashSlot("key") compiling, and binding to it.
Fixes seredis#3365.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XUNs4qcAQaGCRpkwmr8LnY
This branch has not been deployed
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.
Fixes #3365.
There was no public way to ask which hash slot a
RedisChannelis routed by. The usual workaround isHashSlot(new RedisKey(channel)), which hashes the channel's name as a key. It gets two cases wrong: a configuredChannelPrefix, and single-key keyspace channels, which are routed by their key. This exposes the existingServerSelectionStrategy.HashSlot(in RedisChannel), which is what routing actually uses and handles both.Changes
IConnectionMultiplexer.HashSlot(RedisChannel), implemented byConnectionMultiplexer(delegating toServerSelectionStrategy.HashSlot(in RedisChannel)). Also forwarded byMultiGroupMultiplexerand the test fixture'sNonDisposingConnection.[OverloadResolutionPriority(1)]on the existingHashSlot(RedisKey), on both the interface andConnectionMultiplexer.stringandbyte[]convert implicitly to bothRedisKeyandRedisChannel; the channel conversions are[Obsolete], but that doesn't remove them from overload resolution. Without the attribute,HashSlot("key")becomes ambiguous (CS0121). I checked this: removing it breaks existing calls inClusterTestsandHotKeysTests. This follows the precedent ofRedisChannel.KeySpacePrefix, including the framework shim for older TFMs.PublicAPI.Unshipped.txtentries.Things worth a reviewer's eye
IConnectionMultiplexer, which is a break for anyone implementing it outside the library. Happy to change the shape (e.g. an extension method) if you'd rather avoid that.string/byte[]arguments.HashSlot(RedisKey), it returns-1when not connected to a cluster.Testing
ChannelHashSlotUnitTests, against the in-process server in cluster mode:ChannelPrefix, its slot is the prefixed name's;KeySpaceSingleKeychannel has its key's slot;-1;stringandbyte[]arguments still bind to the key overload, both throughConnectionMultiplexerand through the interface.StackExchange.Redis's TFMs with no warnings.*UnitTestsclasses pass (1225, including the 5 new ones) onnet10.0.Checklist