Skip to content

Commit 5141a50

Browse files
committed
fix(doctests): correct API usage and return values in json and list examples
- Fix dt-json.js: use options object for json.type, json.strLen, json.del, json.arrPop, json.objLen, json.objKeys - Fix dt-json.js: correct json.del return value from [1] to 1 - Fix dt-list.js: correct client initialization, return values (null, OK, 1), and error type - Replace deprecated client.quit() with client.close() in both files
1 parent 34b3f01 commit 5141a50

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

doctests/dt-json.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ console.log(res1); // OK
1919
const res2 = await client.json.get("bike", { path: "$" });
2020
console.log(res2); // ['"Hyperion"']
2121

22-
const res3 = await client.json.type("bike", "$");
22+
const res3 = await client.json.type("bike", { path: "$" });
2323
console.log(res3); // [ 'string' ]
2424
// STEP_END
2525

@@ -28,7 +28,7 @@ assert.deepEqual(res2, ['"Hyperion"']);
2828
// REMOVE_END
2929

3030
// STEP_START str
31-
const res4 = await client.json.strLen("bike", "$");
31+
const res4 = await client.json.strLen("bike", { path: "$" });
3232
console.log(res4) // [10]
3333

3434
const res5 = await client.json.strAppend("bike", '" (Enduro bikes)"');
@@ -70,8 +70,8 @@ console.log(res12); // [[ 'Deimos', { crashes: 0 }, null ]]
7070
const res13 = await client.json.get("newbike", { path: "$[1].crashes" });
7171
console.log(res13); // [0]
7272

73-
const res14 = await client.json.del("newbike", "$.[-1]");
74-
console.log(res14); // [1]
73+
const res14 = await client.json.del("newbike", { path: "$.[-1]"} );
74+
console.log(res14); // 1
7575

7676
const res15 = await client.json.get("newbike", { path: "$" });
7777
console.log(res15); // [[ 'Deimos', { crashes: 0 } ]]
@@ -105,10 +105,10 @@ console.log(res21); // [1]
105105
const res22 = await client.json.get("riders", { path: "$" });
106106
console.log(res22); // [[ 'Prickett' ]]
107107

108-
const res23 = await client.json.arrPop("riders", "$");
108+
const res23 = await client.json.arrPop("riders", { path: "$" });
109109
console.log(res23); // [ 'Prickett' ]
110110

111-
const res24 = await client.json.arrPop("riders", "$");
111+
const res24 = await client.json.arrPop("riders", { path: "$" });
112112
console.log(res24); // [null]
113113
// STEP_END
114114

@@ -126,10 +126,10 @@ const res25 = await client.json.set(
126126
);
127127
console.log(res25); // OK
128128

129-
const res26 = await client.json.objLen("bike:1", "$");
129+
const res26 = await client.json.objLen("bike:1", { path: "$" });
130130
console.log(res26); // [3]
131131

132-
const res27 = await client.json.objKeys("bike:1", "$");
132+
const res27 = await client.json.objKeys("bike:1", { path: "$" });
133133
console.log(res27); // [['model', 'brand', 'price']]
134134
// STEP_END
135135

@@ -421,5 +421,5 @@ assert.deepEqual(res42, [
421421
["black", "white"],
422422
["black", "silver", "pink"],
423423
]);
424-
await client.quit();
424+
await client.close();
425425
// REMOVE_END

doctests/dt-list.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import assert from 'assert';
44
import { createClient } from 'redis';
55

6-
const client = await createClient();
6+
const client = createClient();
77
await client.connect();
88
// HIDE_END
99
// REMOVE_START
@@ -150,7 +150,7 @@ const res25 = await client.rPop('bikes:repairs');
150150
console.log(res25); // 'bike:2'
151151

152152
const res26 = await client.rPop('bikes:repairs');
153-
console.log(res26); // None
153+
console.log(res26); // null
154154
// STEP_END
155155

156156
// REMOVE_START
@@ -168,7 +168,7 @@ const res27 = await client.lPush(
168168
console.log(res27); // 5
169169

170170
const res28 = await client.lTrim('bikes:repairs', 0, 2);
171-
console.log(res28); // true
171+
console.log(res28); // OK
172172

173173
const res29 = await client.lRange('bikes:repairs', 0, -1);
174174
console.log(res29); // ['bike:5', 'bike:4', 'bike:3']
@@ -248,7 +248,7 @@ console.log(res38); // 'string'
248248
try {
249249
const res39 = await client.lPush('new_bikes', 'bike:2', 'bike:3');
250250
// redis.exceptions.ResponseError:
251-
// [ErrorReply: WRONGTYPE Operation against a key holding the wrong kind of value]
251+
// [SimpleError: WRONGTYPE Operation against a key holding the wrong kind of value]
252252
}
253253
catch(e){
254254
console.log(e);
@@ -266,7 +266,7 @@ await client.lPush('bikes:repairs', ['bike:1', 'bike:2', 'bike:3']);
266266
console.log(res36); // 3
267267

268268
const res40 = await client.exists('bikes:repairs')
269-
console.log(res40); // true
269+
console.log(res40); // 1
270270

271271
const res41 = await client.lPop('bikes:repairs');
272272
console.log(res41); // 'bike:3'
@@ -282,7 +282,7 @@ console.log(res44); // 0
282282
// STEP_END
283283

284284
// REMOVE_START
285-
assert.equal(res40, true);
285+
assert.equal(res40, 1);
286286
assert.equal(res41, 'bike:3');
287287
assert.equal(res42, 'bike:2');
288288
assert.equal(res43, 'bike:1');
@@ -325,5 +325,5 @@ assert.equal(res48, 5);
325325
assert.equal(res49, 'OK');
326326
assert.deepEqual(res50, ['bike:5', 'bike:4', 'bike:3']);
327327
await client.del('bikes:repairs');
328-
await client.quit();
328+
await client.close();
329329
// REMOVE_END

0 commit comments

Comments
 (0)