Skip to content

Fix hScanValuesIterator to yield values instead of field names#3344

Merged
nkaradzhov merged 2 commits into
redis:masterfrom
winklemad:fix-hscan-values-iterator
Jul 21, 2026
Merged

Fix hScanValuesIterator to yield values instead of field names#3344
nkaradzhov merged 2 commits into
redis:masterfrom
winklemad:fix-hscan-values-iterator

Conversation

@winklemad

@winklemad winklemad commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

hScanValuesIterator() was a copy of hScanNoValuesIterator(): it called hScanNoValues() (which issues HSCAN ... NOVALUES, a reply that by protocol contains only field names) and yielded reply.fields. As a result it returned hash field names — byte-for-byte identical to hScanNoValuesIterator — instead of the values it is named for.

hScanIterator (entries) and hScanNoValuesIterator (field names) were both correct; only the values-only variant was wrong.

Fix

Iterate the full HSCAN, exactly like hScanIterator already does, and yield the values:

-      const reply = await this.hScanNoValues(key, cursor, options);
+      const reply = await this.hScan(key, cursor, options);
       cursor = reply.cursor;
-      yield reply.fields;
+      yield reply.entries.map(entry => entry.value);

Behavior for a hash { f1: 'v1', f2: 'v2' }

before after
hScanValuesIterator yields ['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
hScanValuesIterator was implemented like hScanNoValuesIterator: it used hScanNoValues (HSCAN … NOVALUES) and yielded reply.fields, so callers got field names instead of values.

The iterator now uses full hScan (same pattern as hScanIterator) and yields reply.entries.map(entry => entry.value) per page.

An integration test hScanValuesIterator asserts a 100-field hash returns all expected valueN strings.

Reviewed by Cursor Bugbot for commit b57c4f5. Bugbot is set up for automated code reviews on this repo. Configure here.

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 nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.
@winklemad

Copy link
Copy Markdown
Contributor Author

Thanks @nkaradzhov — added the regression test in b57c4f5, mirroring the existing hScanNoValuesIterator test. It uses distinct field/value pairs (value${i}) and asserts the iterator yields the hash values, so it fails against the old field-name behavior and passes with the fix. Re-requesting review whenever you have a moment.

@nkaradzhov nkaradzhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @winklemad, looks good!

@nkaradzhov
nkaradzhov merged commit a895dcf into redis:master Jul 21, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hScanValuesIterator yields field names instead of values

2 participants