Skip to content

Commit 4ba3d8c

Browse files
committed
fix(doctests): update cmds-generic.js and cmds-cnxmgmt.js for v5 compliance
- Replace deprecated client.quit() with client.close() - Update sScanIterator to use collection-yielding behavior (value -> values) - Fix HSCAN API changes: tuples renamed to entries - Fix cursor type issues: use string '0' instead of number 0 for hScan - Fix infinite loop in scan cleanup by using do-while pattern
1 parent e3b26ab commit 4ba3d8c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

doctests/cmds-cnxmgmt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ await client.sendCommand(['ACL', 'DELUSER', 'test-user']);
4545
// STEP_END
4646

4747
// HIDE_START
48-
await client.quit();
48+
await client.close();
4949
// HIDE_END

doctests/cmds-generic.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ const scan1Res1 = await client.sAdd('myset', ['1', '2', '3', 'foo', 'foobar', 'f
9292
console.log(scan1Res1); // 6
9393

9494
let scan1Res2 = [];
95-
for await (const value of client.sScanIterator('myset', { MATCH: 'f*' })) {
96-
scan1Res2 = scan1Res2.concat(value);
95+
for await (const values of client.sScanIterator('myset', { MATCH: 'f*' })) {
96+
scan1Res2 = scan1Res2.concat(values);
9797
}
9898
console.log(scan1Res2); // ['foo', 'foobar', 'feelsgood']
9999
// REMOVE_START
@@ -129,15 +129,15 @@ console.log(scanResult.cursor, scanResult.keys);
129129
console.assert(scanResult.keys.length === 18);
130130
cursor = '0';
131131
const prefix = 'key:*';
132-
while (cursor !== '0') {
132+
do {
133133
scanResult = await client.scan(cursor, { MATCH: prefix, COUNT: 1000 });
134134
console.log(scanResult.cursor, scanResult.keys);
135135
cursor = scanResult.cursor;
136136
const keys = scanResult.keys;
137137
if (keys.length) {
138138
await client.del(keys);
139139
}
140-
}
140+
} while (cursor !== '0');
141141
// REMOVE_END
142142
// STEP_END
143143

@@ -172,17 +172,17 @@ await client.del(['geokey', 'zkey']);
172172
const scan4Res1 = await client.hSet('myhash', { a: 1, b: 2 });
173173
console.log(scan4Res1); // 2
174174

175-
const scan4Res2 = await client.hScan('myhash', 0);
176-
console.log(scan4Res2.tuples); // [{field: 'a', value: '1'}, {field: 'b', value: '2'}]
175+
const scan4Res2 = await client.hScan('myhash', '0');
176+
console.log(scan4Res2.entries); // [{field: 'a', value: '1'}, {field: 'b', value: '2'}]
177177
// REMOVE_START
178-
assert.deepEqual(scan4Res2.tuples, [
178+
assert.deepEqual(scan4Res2.entries, [
179179
{ field: 'a', value: '1' },
180180
{ field: 'b', value: '2' }
181181
]);
182182
// REMOVE_END
183183

184-
const scan4Res3 = await client.hScan('myhash', 0, { COUNT: 10 });
185-
const items = scan4Res3.tuples.map((item) => item.field)
184+
const scan4Res3 = await client.hScan('myhash', '0', { COUNT: 10 });
185+
const items = scan4Res3.entries.map((item) => item.field)
186186
console.log(items); // ['a', 'b']
187187
// REMOVE_START
188188
assert.deepEqual(items, ['a', 'b'])
@@ -191,5 +191,5 @@ await client.del('myhash');
191191
// STEP_END
192192

193193
// HIDE_START
194-
await client.quit();
194+
await client.close();
195195
// HIDE_END

0 commit comments

Comments
 (0)