perf: store Redis buffers without base64#10
Merged
Conversation
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.
Summary
DialCache serializers already support
string | Buffer, but the Redis path converted every Buffer to base64 before invoking Lua and decoded it after reads. That expanded binary payloads by roughly one third and added avoidable allocations on both sides of Redis.This change stores Buffer serializer output byte-for-byte while keeping the existing one-round-trip, Lua-backed cache protocol.
Closes #6.
Design
Semantic Redis client boundary
DialCacheRedisClientnow exchanges serialized cache payloads directly asstring | Buffer.Core DialCache no longer exposes or interprets Redis wire encodings. It passes serializer output unchanged to the configured semantic client and passes the client's decoded payload directly to
serializer.load.This keeps the boundary independent of node-redis. A future Valkey GLIDE adapter can use GLIDE's own script lifecycle, cluster routing, and byte decoder while implementing the same semantic interface.
Wire protocol
The existing frame version and key suffix remain unchanged because DialCache is new and has no deployed compatibility requirement:
Encoding 1 previously identified base64 text. It now identifies raw binary. No migration or mixed-version compatibility layer is included.
Lua continues to:
node-redis adapter
The node-redis adapter now:
The public protocol export renames
REDIS_ENCODING_BASE64toREDIS_ENCODING_BINARY.Behavior and compatibility
DialCacheRedisPayloadEncodingErrorpath and metrics label.Performance
A directional sequential write/read benchmark against local Redis 6.2 showed:
These local Docker results are directional rather than production latency predictions. Stored size is deterministically the payload plus the 10-byte frame header.
Validation
corepack pnpm typecheckcorepack pnpm test— 90 unit tests with coverage thresholdscorepack pnpm buildcorepack pnpm test:packagecorepack pnpm test:integration— 35 tests across:corepack pnpm audit --prod— no known vulnerabilitiesgit diff --check