Fix hScanValuesIterator to yield values instead of field names#3344
Conversation
hScanValuesIterator was a copy of hScanNoValuesIterator: it called hScanNoValues() (HSCAN ... NOVALUES, whose reply by protocol contains only field names) and yielded reply.fields, so it returned field names instead of the hash values it is named for. Iterate the full HSCAN, like hScanIterator does, and yield the values. Fixes redis#3343
nkaradzhov
left a comment
There was a problem hiding this comment.
@winklemad thanks for the PR!
One change needed before merge: please add a regression test in packages/client/lib/client/index.spec.ts, following the existing hScanIterator / hScanNoValuesIterator tests (testUtils.testWithClient), asserting that the iterator yields the hash values. Happy to merge once that's in.
Uses distinct field/value pairs and asserts the iterator yields the hash values, so it fails against the previous field-name behavior.
|
Thanks @nkaradzhov — added the regression test in b57c4f5, mirroring the existing |
nkaradzhov
left a comment
There was a problem hiding this comment.
Thanks @winklemad, looks good!
hScanValuesIterator()was a copy ofhScanNoValuesIterator(): it calledhScanNoValues()(which issuesHSCAN ... NOVALUES, a reply that by protocol contains only field names) and yieldedreply.fields. As a result it returned hash field names — byte-for-byte identical tohScanNoValuesIterator— instead of the values it is named for.hScanIterator(entries) andhScanNoValuesIterator(field names) were both correct; only the values-only variant was wrong.Fix
Iterate the full
HSCAN, exactly likehScanIteratoralready does, and yield the values:Behavior for a hash
{ f1: 'v1', f2: 'v2' }hScanValuesIteratoryields['f1', 'f2'](field names)['v1', 'v2'](values)Fixes #3343
Note
Low Risk
Small, localized bugfix to a misnamed iterator with a new integration test; behavior change only affects callers that relied on the incorrect field-name output.
Overview
hScanValuesIteratorwas implemented likehScanNoValuesIterator: it usedhScanNoValues(HSCAN … NOVALUES) and yieldedreply.fields, so callers got field names instead of values.The iterator now uses full
hScan(same pattern ashScanIterator) and yieldsreply.entries.map(entry => entry.value)per page.An integration test
hScanValuesIteratorasserts a 100-field hash returns all expectedvalueNstrings.Reviewed by Cursor Bugbot for commit b57c4f5. Bugbot is set up for automated code reviews on this repo. Configure here.