Skip to content

Commit 271baf3

Browse files
sjpotterleibale
andauthored
HSCAN NOVALUES support (v5) (#2758)
* HSCAN VALUES support (v5) * add hscanNoValuesIterator * nitpick --------- Co-authored-by: Leibale Eidelman <[email protected]>
1 parent 31c881e commit 271baf3

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

packages/client/lib/client/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,19 @@ export default class RedisClient<
901901
} while (cursor !== '0');
902902
}
903903

904+
async* hScanValuesIterator(
905+
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
906+
key: RedisArgument,
907+
options?: ScanCommonOptions & ScanIteratorOptions
908+
) {
909+
let cursor = options?.cursor ?? '0';
910+
do {
911+
const reply = await this.hScanNoValues(key, cursor, options);
912+
cursor = reply.cursor;
913+
yield reply.fields;
914+
} while (cursor !== '0');
915+
}
916+
904917
async* sScanIterator(
905918
this: RedisClientType<M, F, S, RESP, TYPE_MAPPING>,
906919
key: RedisArgument,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { strict as assert } from 'node:assert';
2+
import testUtils, { GLOBAL } from '../test-utils';
3+
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
4+
5+
describe('HSCAN_NOVALUES', () => {
6+
describe('transformArguments', () => {
7+
it('cusror only', () => {
8+
assert.deepEqual(
9+
HSCAN_NOVALUES.transformArguments('key', '0'),
10+
['HSCAN', 'key', '0', 'NOVALUES']
11+
);
12+
});
13+
14+
it('with MATCH', () => {
15+
assert.deepEqual(
16+
HSCAN_NOVALUES.transformArguments('key', '0', {
17+
MATCH: 'pattern'
18+
}),
19+
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'NOVALUES']
20+
);
21+
});
22+
23+
it('with COUNT', () => {
24+
assert.deepEqual(
25+
HSCAN_NOVALUES.transformArguments('key', '0', {
26+
COUNT: 1
27+
}),
28+
['HSCAN', 'key', '0', 'COUNT', '1', 'NOVALUES']
29+
);
30+
});
31+
32+
it('with MATCH & COUNT', () => {
33+
assert.deepEqual(
34+
HSCAN_NOVALUES.transformArguments('key', '0', {
35+
MATCH: 'pattern',
36+
COUNT: 1
37+
}),
38+
['HSCAN', 'key', '0', 'MATCH', 'pattern', 'COUNT', '1', 'NOVALUES']
39+
);
40+
});
41+
});
42+
43+
testUtils.testWithClient('client.hScanNoValues', async client => {
44+
const [, reply] = await Promise.all([
45+
client.hSet('key', 'field', 'value'),
46+
client.hScanNoValues('key', '0')
47+
]);
48+
49+
assert.deepEqual(reply, {
50+
cursor: '0',
51+
fields: [
52+
'field',
53+
]
54+
});
55+
}, GLOBAL.SERVERS.OPEN);
56+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { RedisArgument, BlobStringReply, Command } from '../RESP/types';
2+
import { ScanCommonOptions, pushScanArguments } from './SCAN';
3+
4+
export default {
5+
FIRST_KEY_INDEX: 1,
6+
IS_READ_ONLY: true,
7+
transformArguments(
8+
key: RedisArgument,
9+
cursor: RedisArgument,
10+
options?: ScanCommonOptions
11+
) {
12+
const args = pushScanArguments(['HSCAN', key], cursor, options);
13+
args.push('NOVALUES');
14+
return args;
15+
},
16+
transformReply([cursor, fields]: [BlobStringReply, Array<BlobStringReply>]) {
17+
return {
18+
cursor,
19+
fields
20+
};
21+
}
22+
} as const satisfies Command;

packages/client/lib/commands/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ import HRANDFIELD_COUNT_WITHVALUES from './HRANDFIELD_COUNT_WITHVALUES';
144144
import HRANDFIELD_COUNT from './HRANDFIELD_COUNT';
145145
import HRANDFIELD from './HRANDFIELD';
146146
import HSCAN from './HSCAN';
147+
import HSCAN_NOVALUES from './HSCAN_NOVALUES';
147148
import HSET from './HSET';
148149
import HSETNX from './HSETNX';
149150
import HSTRLEN from './HSTRLEN';
@@ -623,6 +624,8 @@ export default {
623624
hRandField: HRANDFIELD,
624625
HSCAN,
625626
hScan: HSCAN,
627+
HSCAN_NOVALUES,
628+
hScanNoValues: HSCAN_NOVALUES,
626629
HSET,
627630
hSet: HSET,
628631
HSETNX,

0 commit comments

Comments
 (0)