Repository navigation
fix(incremental): read tag states with one MGET; per-key only on Cluster - #36
Merged
Merged
Conversation
…ter (#34) The ISR handler read each tag's state with its own GET: one round trip thanks to auto-pipelining, but one command per tag, and a page carries an implicit _N_T_ tag per layout segment. That is six to seven times the command count of other handlers under the same traffic, which is what per-command pricing and command-rate limits see. Per-key reads stay for Redis Cluster, where the un-namespaced tag keys never share a slot: from the start when the adapter is flagged isCluster (new on RedisClientLike) or hashTag is set, otherwise from the first CROSSSLOT reply on, retried in place. ioredis with auto-pipelining refuses client-side with a different message, which is recognised too.
leejpsd
force-pushed
the
fix/isr-tag-read-mget
branch
from
November 24, 2026 01:46
a85a408 to
cbac5a5
Compare
QA against a real Redis: with an ACL user that may GET but not MGET, every multi-tag read fell through to the local tag mirror, so a hard revalidateTag from a second handler was not seen. Releases up to 1.1.0 read key by key and were not affected. NOPERM, an unknown command, a client without mGet and a reply that is not one value per key now latch to per-key reads the same way CROSSSLOT does, retrying that read in place. Timeouts and dropped connections still fall back without latching. Concurrent first reads warn once.
Merged
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.
Follow-up to #34. Marko's benchmark put this handler at six to seven times fortedigital's Redis command count for the same steady traffic. The ISR handler read each tag's state with its own GET: auto-pipelined, so one round trip, but one command per tag, and a page carries an implicit
_N_T_tag for every layout segment on top of its own tags. With per-command pricing (Upstash) or command-rate limits, that count is the bill.The per-key reads were there for Redis Cluster: ISR tag keys are deliberately un-namespaced so
revalidateTagsurvives a deploy, which means they never share a hash slot and a multi-keyMGETis refused withCROSSSLOT. That is a Cluster constraint, not a reason to pay per tag on a single node.What changes
readTagStatesreads all of an entry's tags with oneMGET. A single tag stays a plainGET.isClusterflag thatadaptClustersets onRedisClientLike, or fromhashTag: true. A raw Cluster client passed through a factory without either is caught on its first refusal: the handler latches to per-key reads for good, retries that read in place so nothing is lost, and logs one warning.CROSSSLOT ..., and ioredis's client-sideAll the keys in a pipeline command should belong to the same slot, which is what you actually get withenableAutoPipelining: true(found by running it against the 3-master cluster).MGETcan never work: a Redis user whose ACL allowsGETbut notMGET(NOPERM), a server or proxy that does not know the command, and a custom client whosemGetis missing or does not return one value per key. Without it those reads would fall back to the local tag mirror every time and miss invalidations made by other instances. I hit the ACL case in QA against a real Redis: a hardrevalidateTagon a second handler was not seen by the first until this was added.tag.expiration.readis now emitted by the ISR handler too, withmeta.strategy: "mget" | "per-key".Commands per
get()scripts/bench-isr-tag-read.mjs, local Redis 7, 200 reads per row, entry GET included:Round trips are unchanged (one either way); only the command count moves.
Tests
tests/unit/isr-tag-read.test.ts, 17): one MGET per read, no tag keys touched for a tag-less entry, single tag is a GET, soft and hard invalidations from another instance still land through the MGET path,hashTag: trueandisClusterstart per-key, both cross-slot spellings latch without losing the read,NOPERM/ unknown command / missingmGet/ malformed reply latch, concurrent refusals warn once, a timeout and other errors fall back without latching, per-key reads after a latch still honour invalidations.tests/integration/isr-tag-read.test.ts, redis@5 and ioredis): one MGET with three keys per read; hard and softrevalidateTagfrom a second instance seen by the first; a real ACL user with-mgetstill sees a second instance's hard invalidation.tests/cluster/cluster.test.ts, +2): the cluster adapter never issues an MGET and still sees a hard invalidation; an adapter with the flag hidden hits the refusal once, latches, and later reads make no second probe.Patch changeset. No option changes;
hashTagkeeps its meaning and gains a documented side effect in the README, API reference and agent skill.