feat: support Uint8Array in command arguments#2120
Open
x-at-01 wants to merge 4 commits into
Open
Conversation
Convert raw Uint8Array instances in command arguments and keyPrefixes to Buffer instances using a zero-copy operation. This allows raw Uint8Array data to be set and read seamlessly just like standard Buffers.
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 7ec206d. Configure here.
Contributor
|
@xtco3o Thanks for the PR. I’ll take a look and review it. In the meantime, please check any Cursor bot comments and address them if needed. |
This prevents Uint8Array.prototype.toString() from returning a comma-separated decimal byte string, which would cause incorrect hash slot calculations in cluster mode.
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.

Description
This pull request adds support for raw
Uint8Arrayinstances as command arguments and key prefixes.Since Node's
Bufferinherits fromUint8Array, we detect instances ofUint8Arraythat are notBuffers and convert them toBufferviews. This conversion uses a zero-copy operation:This ensures high performance and zero memory copying overhead.
Usage Example
Changes
lib/utils/buffer.tsto recursively convertUint8Arrayinside standard arrays,Maps, and plain object literals.CommandParameterandArgumentTypeto supportUint8Arraytypes.Commandconstructor to map command arguments and convertoptions.keyPrefix.stringifyArgumentsto convert any remainingUint8Arrayarguments toBuffer.test/unit/command.tsto coverUint8Arrayargs, objects, maps, and key prefix inputs.Note
Low Risk
Localized argument normalization and type extensions; existing Buffer paths unchanged, with unit tests covering encoding and cluster key extraction.
Overview
Adds first-class support for non-Buffer
Uint8Arrayvalues in Redis command arguments andkeyPrefix, converting them toBuffervia zero-copyBuffer.from(buffer, byteOffset, byteLength)so binary payloads work without callers manually wrapping buffers.New helpers in
lib/utils/buffer.tsrecursively normalizeUint8Arrayin arrays, plain objects, andMaps.Commandapplies this on flatten, instringifyArguments(including buffer-mode wire encoding), and forkeyPrefix. Auto-pipelining key/slot routing now normalizesUint8Arraykeys the same way, withgetFirstKeyForCommandexported for tests.Reviewed by Cursor Bugbot for commit 4391f5d. Bugbot is set up for automated code reviews on this repo. Configure here.