Skip to content

Commit 2c00ba2

Browse files
committed
fix(doctests): update dt-streams.js object shapes and parameters for v5 compliance
- Update stream result objects from tuple format to proper object format with id/message properties - Change xRead/xReadGroup results from nested arrays to objects with name/messages structure - Update xAutoClaim results to use nextId, messages, and deletedMessages properties - Add missing properties to xInfo* results (max-deleted-entry-id, entries-added, recorded-first-entry-id, entries-read, lag, inactive) - Modernize parameter names (count -> COUNT, block -> BLOCK, etc.) - Update MAXLEN/APPROXIMATE options to new TRIM object structure - Fix error message format for XADD duplicate ID error - Update boolean return values (True -> OK)
1 parent 4ba3d8c commit 2c00ba2

File tree

1 file changed

+64
-44
lines changed

1 file changed

+64
-44
lines changed

doctests/dt-streams.js

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ assert.equal(await client.xLen('race:france'), 3);
5050

5151
// STEP_START xRange
5252
const res4 = await client.xRange('race:france', '1691765278160-0', '+', {COUNT: 2});
53-
console.log(res4); // >>> [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'}), ('1692629594113-0', {'rider': 'Norem', 'speed': '28.8', 'position': '3', 'location_id': '1'})]
53+
console.log(res4); // >>> [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }, { id: '1692629594113-0', message: { rider: 'Norem', speed: '28.8', position: '3', location_id: '1' } }]
5454
// STEP_END
5555

5656
// STEP_START xread_block
5757
const res5 = await client.xRead({
5858
key: 'race:france',
5959
id: '0-0'
6060
}, {
61-
count: 100,
62-
block: 300
61+
COUNT: 100,
62+
BLOCK: 300
6363
});
64-
console.log(res5); // >>> [['race:france', [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'}), ('1692629594113-0', {'rider': 'Norem', 'speed': '28.8', 'position': '3', 'location_id': '1'}), ('1692629613374-0', {'rider': 'Prickett', 'speed': '29.7', 'position': '2', 'location_id': '1'})]]]
64+
console.log(res5); // >>> [{ name: 'race:france', messages: [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }, { id: '1692629594113-0', message: { rider: 'Norem', speed: '28.8', position: '3', location_id: '1' } }, { id: '1692629613374-0', message: { rider: 'Prickett', speed: '29.7', position: '2', location_id: '1' } }] }]
6565
// STEP_END
6666

6767
// STEP_START xAdd_2
@@ -101,7 +101,7 @@ try {
101101
});
102102
console.log(res10); // >>> 0-1
103103
} catch (error) {
104-
console.error(error); // >>> WRONGID
104+
console.error(error); // >>> [SimpleError: ERR The ID specified in XADD is equal or smaller than the target stream top item]
105105
}
106106
// STEP_END
107107

@@ -112,22 +112,22 @@ console.log(res11a); // >>> 0-3
112112

113113
// STEP_START xRange_all
114114
const res11 = await client.xRange('race:france', '-', '+');
115-
console.log(res11); // >>> [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'}), ('1692629594113-0', {'rider': 'Norem', 'speed': '28.8', 'position': '3', 'location_id': '1'}), ('1692629613374-0', {'rider': 'Prickett', 'speed': '29.7', 'position': '2', 'location_id': '1'}), ('1692629676124-0', {'rider': 'Castilla', 'speed': '29.9', 'position': '1', 'location_id': '2'})]
115+
console.log(res11); // >>> [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }, { id: '1692629594113-0', message: { rider: 'Norem', speed: '28.8', position: '3', location_id: '1' } }, { id: '1692629613374-0', message: { rider: 'Prickett', speed: '29.7', position: '2', location_id: '1' } }, { id: '1692629676124-0', message: { rider: 'Castilla', speed: '29.9', position: '1', location_id: '2' } }]
116116
// STEP_END
117117

118118
// STEP_START xRange_time
119119
const res12 = await client.xRange('race:france', '1692629576965', '1692629576967');
120-
console.log(res12); // >>> [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'})]
120+
console.log(res12); // >>> [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }]
121121
// STEP_END
122122

123123
// STEP_START xRange_step_1
124124
const res13 = await client.xRange('race:france', '-', '+', {COUNT: 2});
125-
console.log(res13); // >>> [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'}), ('1692629594113-0', {'rider': 'Norem', 'speed': '28.8', 'position': '3', 'location_id': '1'})]
125+
console.log(res13); // >>> [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }, { id: '1692629594113-0', message: { rider: 'Norem', speed: '28.8', position: '3', location_id: '1' } }]
126126
// STEP_END
127127

128128
// STEP_START xRange_step_2
129129
const res14 = await client.xRange('race:france', '(1692629594113-0', '+', {COUNT: 2});
130-
console.log(res14); // >>> [('1692629613374-0', {'rider': 'Prickett', 'speed': '29.7', 'position': '2', 'location_id': '1'}), ('1692629676124-0', {'rider': 'Castilla', 'speed': '29.9', 'position': '1', 'location_id': '2'})]
130+
console.log(res14); // >>> [{ id: '1692629613374-0', message: { rider: 'Prickett', speed: '29.7', position: '2', location_id: '1' } }, { id: '1692629676124-0', message: { rider: 'Castilla', speed: '29.9', position: '1', location_id: '2' } }]
131131
// STEP_END
132132

133133
// STEP_START xRange_empty
@@ -139,29 +139,29 @@ console.log(res15); // >>> []
139139
const res16 = await client.xRevRange('race:france', '+', '-', {COUNT: 1});
140140
console.log(
141141
res16
142-
); // >>> [('1692629676124-0', {'rider': 'Castilla', 'speed': '29.9', 'position': '1', 'location_id': '2'})]
142+
); // >>> [{ id: '1692629676124-0', message: { rider: 'Castilla', speed: '29.9', position: '1', location_id: '2' } }]
143143
// STEP_END
144144

145145
// STEP_START xread
146146
const res17 = await client.xRead({
147147
key: 'race:france',
148148
id: '0-0'
149149
}, {
150-
count: 2
150+
COUNT: 2
151151
});
152-
console.log(res17); // >>> [['race:france', [('1692629576966-0', {'rider': 'Castilla', 'speed': '30.2', 'position': '1', 'location_id': '1'}), ('1692629594113-0', {'rider': 'Norem', 'speed': '28.8', 'position': '3', 'location_id': '1'})]]]
152+
console.log(res17); // >>> [{ name: 'race:france', messages: [{ id: '1692629576966-0', message: { rider: 'Castilla', speed: '30.2', position: '1', location_id: '1' } }, { id: '1692629594113-0', message: { rider: 'Norem', speed: '28.8', position: '3', location_id: '1' } }] }]
153153
// STEP_END
154154

155155
// STEP_START xgroup_create
156156
const res18 = await client.xGroupCreate('race:france', 'france_riders', '$');
157-
console.log(res18); // >>> True
157+
console.log(res18); // >>> OK
158158
// STEP_END
159159

160160
// STEP_START xgroup_create_mkstream
161161
const res19 = await client.xGroupCreate('race:italy', 'italy_riders', '$', {
162-
'MKSTREAM': true
162+
MKSTREAM: true
163163
});
164-
console.log(res19); // >>> True
164+
console.log(res19); // >>> OK
165165
// STEP_END
166166

167167
// STEP_START xgroup_read
@@ -187,10 +187,10 @@ const res20 = await client.xReadGroup(
187187
key: 'race:italy',
188188
id: '>'
189189
}, {
190-
'COUNT': 1
190+
COUNT: 1
191191
}
192192
);
193-
console.log(res20); // >>> [['race:italy', [('1692629925771-0', {'rider': 'Castilla'})]]]
193+
console.log(res20); // >>> [{ name: 'race:italy', messages: [{ id: '1692629925771-0', message: { rider: 'Castilla' } }] }]
194194
// STEP_END
195195

196196
// STEP_START xgroup_read_id
@@ -200,10 +200,10 @@ const res21 = await client.xReadGroup(
200200
key: 'race:italy',
201201
id: '0'
202202
}, {
203-
'COUNT': 1
203+
COUNT: 1
204204
}
205205
);
206-
console.log(res21); // >>> [['race:italy', [('1692629925771-0', {'rider': 'Castilla'})]]]
206+
console.log(res21); // >>> [{ name: 'race:italy', messages: [{ id: '1692629925771-0', message: { rider: 'Castilla' } }] }]
207207
// STEP_END
208208

209209
// STEP_START xack
@@ -216,10 +216,10 @@ const res23 = await client.xReadGroup(
216216
key: 'race:italy',
217217
id: '0'
218218
}, {
219-
'COUNT': 1
219+
COUNT: 1
220220
}
221221
);
222-
console.log(res23); // >>> [['race:italy', []]]
222+
console.log(res23); // >>> [{ name: 'race:italy', messages: [] }]
223223
// STEP_END
224224

225225
// STEP_START xgroup_read_bob
@@ -229,98 +229,118 @@ const res24 = await client.xReadGroup(
229229
key: 'race:italy',
230230
id: '>'
231231
}, {
232-
'COUNT': 2
232+
COUNT: 2
233233
}
234234
);
235-
console.log(res24); // >>> [['race:italy', [('1692629925789-0', {'rider': 'Royce'}), ('1692629925790-0', {'rider': 'Sam-Bodden'})]]]
235+
console.log(res24); // >>> [{ name: 'race:italy', messages: [{ id: '1692629925789-0', message: { rider: 'Royce' } }, { id: '1692629925790-0', message: { rider: 'Sam-Bodden' } }] }]
236236
// STEP_END
237237

238238
// STEP_START xpending
239239
const res25 = await client.xPending('race:italy', 'italy_riders');
240-
console.log(res25); // >>> {'pending': 2, 'min': '1692629925789-0', 'max': '1692629925790-0', 'consumers': [{'name': 'Bob', 'pending': 2}]}
240+
console.log(res25); // >>> {'pending': 2, 'firstId': '1692629925789-0', 'lastId': '1692629925790-0', 'consumers': [{'name': 'Bob', 'deliveriesCounter': 2}]}
241241
// STEP_END
242242

243243
// STEP_START xpending_plus_minus
244244
const res26 = await client.xPendingRange('race:italy', 'italy_riders', '-', '+', 10);
245-
console.log(res26); // >>> [{'message_id': '1692629925789-0', 'consumer': 'Bob', 'time_since_delivered': 31084, 'times_delivered': 1}, {'message_id': '1692629925790-0', 'consumer': 'Bob', 'time_since_delivered': 31084, 'times_delivered': 1}]
245+
console.log(res26); // >>> [{'id': '1692629925789-0', 'consumer': 'Bob', 'millisecondsSinceLastDelivery': 31084, 'deliveriesCounter:': 1}, {'id': '1692629925790-0', 'consumer': 'Bob', 'millisecondsSinceLastDelivery': 31084, 'deliveriesCounter': 1}]
246246
// STEP_END
247247

248248
// STEP_START xRange_pending
249249
const res27 = await client.xRange('race:italy', '1692629925789-0', '1692629925789-0');
250-
console.log(res27); // >>> [('1692629925789-0', {'rider': 'Royce'})]
250+
console.log(res27); // >>> [{ id: '1692629925789-0', message: { rider: 'Royce' } }]
251251
// STEP_END
252252

253253
// STEP_START xclaim
254254
const res28 = await client.xClaim(
255255
'race:italy', 'italy_riders', 'Alice', 60000, ['1692629925789-0']
256256
);
257-
console.log(res28); // >>> [('1692629925789-0', {'rider': 'Royce'})]
257+
console.log(res28); // >>> [{ id: '1692629925789-0', message: { rider: 'Royce' } }]
258258
// STEP_END
259259

260260
// STEP_START xautoclaim
261-
const res29 = await client.xAutoClaim('race:italy', 'italy_riders', 'Alice', 1, '0-0', 1);
262-
console.log(res29); // >>> ['1692629925790-0', [('1692629925789-0', {'rider': 'Royce'})]]
261+
const res29 = await client.xAutoClaim('race:italy', 'italy_riders', 'Alice', 1, '0-0', {
262+
COUNT: 1
263+
});
264+
console.log(res29); // >>> { nextId: '1692629925790-0', messages: [{ id: '1692629925789-0', message: { rider: 'Royce' } }], deletedMessages: [] }
263265
// STEP_END
264266

265267
// STEP_START xautoclaim_cursor
266268
const res30 = await client.xAutoClaim(
267-
'race:italy', 'italy_riders', 'Alice', 1, '(1692629925789-0', 1
269+
'race:italy', 'italy_riders', 'Alice', 1, '(1692629925789-0',
270+
{
271+
COUNT: 1
272+
}
268273
);
269-
console.log(res30); // >>> ['0-0', [('1692629925790-0', {'rider': 'Sam-Bodden'})]]
274+
console.log(res30); // >>> { nextId: '0-0', messages: [{ id: '1692629925790-0', message: { rider: 'Sam-Bodden' } }], deletedMessages: [] }
270275
// STEP_END
271276

272277
// STEP_START xinfo
273278
const res31 = await client.xInfoStream('race:italy');
274-
console.log(res31); // >>> {'length': 5, 'radix-tree-keys': 1, 'radix-tree-nodes': 2, 'last-generated-id': '1692629926436-0', 'groups': 1, 'first-entry': ('1692629925771-0', {'rider': 'Castilla'}), 'last-entry': ('1692629926436-0', {'rider': 'Norem'})}
279+
console.log(res31); // >>> { length: 5, 'radix-tree-keys': 1, 'radix-tree-nodes': 2, 'last-generated-id': '1692629926436-0', 'max-deleted-entry-id': '0-0', 'entries-added': 5, 'recorded-first-entry-id': '1692629925771-0', groups: 1, 'first-entry': { id: '1692629925771-0', message: { rider: 'Castilla' } }, 'last-entry': { id: '1692629926436-0', message: { rider: 'Norem' } } }
275280
// STEP_END
276281

277282
// STEP_START xinfo_groups
278283
const res32 = await client.xInfoGroups('race:italy');
279-
console.log(res32); // >>> [{'name': 'italy_riders', 'consumers': 2, 'pending': 2, 'last-delivered-id': '1692629925790-0'}]
284+
console.log(res32); // >>> [{ name: 'italy_riders', consumers: 2, pending: 3, 'last-delivered-id': '1692629925790-0', 'entries-read': 3, lag: 2 }]
280285
// STEP_END
281286

282287
// STEP_START xinfo_consumers
283288
const res33 = await client.xInfoConsumers('race:italy', 'italy_riders');
284-
console.log(res33); // >>> [{'name': 'Alice', 'pending': 2, 'idle': 199332}, {'name': 'Bob', 'pending': 0, 'idle': 489170}]
289+
console.log(res33); // >>> [{ name: 'Alice', pending: 3, idle: 170582, inactive: 170582 }, { name: 'Bob', pending: 0, idle: 489404, inactive: 489404 }]
285290
// STEP_END
286291

287292
// STEP_START maxlen
288293
await client.xAdd('race:italy', '*', {
289294
'rider': 'Jones'
290295
}, {
291-
'MAXLEN': 2
296+
TRIM: {
297+
strategy: 'MAXLEN',
298+
strategyModifier: '~',
299+
threshold: 2
300+
}
292301
});
293302
await client.xAdd('race:italy', '*', {
294303
'rider': 'Wood'
295304
}, {
296-
'MAXLEN': 2
305+
TRIM: {
306+
strategy: 'MAXLEN',
307+
strategyModifier: '~',
308+
threshold: 2
309+
}
297310
});
298311
await client.xAdd('race:italy', '*', {
299312
'rider': 'Henshaw'
300313
}, {
301-
'MAXLEN': 2
314+
TRIM: {
315+
strategy: 'MAXLEN',
316+
strategyModifier: '~',
317+
threshold: 2
318+
}
302319
});
303320

304321
const res34 = await client.xLen('race:italy');
305322
console.log(res34); // >>> 8
306323

307324
const res35 = await client.xRange('race:italy', '-', '+');
308-
console.log(res35); // >>> [('1692629925771-0', {'rider': 'Castilla'}), ('1692629925789-0', {'rider': 'Royce'}), ('1692629925790-0', {'rider': 'Sam-Bodden'}), ('1692629925791-0', {'rider': 'Prickett'}), ('1692629926436-0', {'rider': 'Norem'}), ('1692630612602-0', {'rider': 'Jones'}), ('1692630641947-0', {'rider': 'Wood'}), ('1692630648281-0', {'rider': 'Henshaw'})]
325+
console.log(res35); // >>> [{ id: '1692629925771-0', message: { rider: 'Castilla' } }, { id: '1692629925789-0', message: { rider: 'Royce' } }, { id: '1692629925790-0', message: { rider: 'Sam-Bodden' } }, { id: '1692629925791-0', message: { rider: 'Prickett' } }, { id: '1692629926436-0', message: { rider: 'Norem' } }, { id: '1692630612602-0', message: { rider: 'Jones' } }, { id: '1692630641947-0', message: { rider: 'Wood' } }, { id: '1692630648281-0', message: { rider: 'Henshaw' } }]
309326

310327
await client.xAdd('race:italy', '*', {
311328
'rider': 'Smith'
312329
}, {
313-
'MAXLEN': 2,
314-
'APPROXIMATE': false
330+
TRIM: {
331+
strategy: 'MAXLEN',
332+
strategyModifier: '=',
333+
threshold: 2
334+
}
315335
});
316336

317337
const res36 = await client.xRange('race:italy', '-', '+');
318-
console.log(res36); // >>> [('1692630648281-0', {'rider': 'Henshaw'}), ('1692631018238-0', {'rider': 'Smith'})]
338+
console.log(res36); // >>> [{ id: '1692630648281-0', message: { rider: 'Henshaw' } }, { id: '1692631018238-0', message: { rider: 'Smith' } }]
319339
// STEP_END
320340

321341
// STEP_START xTrim
322342
const res37 = await client.xTrim('race:italy', 'MAXLEN', 10, {
323-
'APPROXIMATE': false
343+
strategyModifier: '=',
324344
});
325345
console.log(res37); // >>> 0
326346
// STEP_END
@@ -332,13 +352,13 @@ console.log(res38); // >>> 0
332352

333353
// STEP_START xDel
334354
const res39 = await client.xRange('race:italy', '-', '+');
335-
console.log(res39); // >>> [('1692630648281-0', {'rider': 'Henshaw'}), ('1692631018238-0', {'rider': 'Smith'})]
355+
console.log(res39); // >>> [{ id: '1692630648281-0', message: { rider: 'Henshaw' } }, { id: '1692631018238-0', message: { rider: 'Smith' } }]
336356

337357
const res40 = await client.xDel('race:italy', '1692631018238-0');
338358
console.log(res40); // >>> 1
339359

340360
const res41 = await client.xRange('race:italy', '-', '+');
341-
console.log(res41); // >>> [('1692630648281-0', {'rider': 'Henshaw'})]
361+
console.log(res41); // >>> [{ id: '1692630648281-0', message: { rider: 'Henshaw' } }]
342362
// STEP_END
343363

344364
// REMOVE_START

0 commit comments

Comments
 (0)