-
Notifications
You must be signed in to change notification settings - Fork 1.9k
DOC-2457 - Adds code examples for the string tutorial #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: emb-examples
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,69 @@ | ||||||
// EXAMPLE: string_tutorial | ||||||
// HIDE_START | ||||||
import assert from 'assert'; | ||||||
import { createClient } from 'redis'; | ||||||
|
||||||
const client = await createClient(); | ||||||
await client.connect(); | ||||||
// HIDE_END | ||||||
// REMOVE_START | ||||||
await client.flushDb(); | ||||||
// REMOVE_END | ||||||
|
||||||
// STEP_START set | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const res1 = await client.set("bike:1", "Deimos"); | ||||||
console.log(res1); // true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in v5, return OK, not true |
||||||
const res2 = await client.get("bike:1"); | ||||||
console.log(res2); // Deimos | ||||||
// STEP_END | ||||||
|
||||||
// REMOVE_START | ||||||
assert.equal(res1, 'OK'); | ||||||
assert.equal(res2, 'Deimos'); | ||||||
// REMOVE_END | ||||||
|
||||||
// STEP_START set_nx_xx | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// HIDE_START | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line. |
||||||
const res3 = await client.set("bike:1", "bike", 'NX'); | ||||||
console.log(res3); // None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure what None means here (checking that its OK below) |
||||||
console.log(await client.get("bike:1")); // Deimos | ||||||
const res4 = await client.set("bike:1", "bike", 'XX'); | ||||||
console.log(res4); // True | ||||||
// STEP_END | ||||||
|
||||||
// REMOVE_START | ||||||
assert.equal(res3, 'OK'); | ||||||
assert.equal(res4, 'OK'); | ||||||
// REMOVE_END | ||||||
|
||||||
// STEP_START mset | ||||||
const res5 = await client.mSet([ | ||||||
["bike:1", "Deimos"], | ||||||
["bike:2", "Ares"], | ||||||
["bike:3", "Vanth"] | ||||||
]); | ||||||
|
||||||
console.log(res5); // true | ||||||
const res6 = await client.mGet(["bike:1", "bike:2", "bike:3"]); | ||||||
console.log(res6); // ['Deimos', 'Ares', 'Vanth'] | ||||||
// STEP_END | ||||||
|
||||||
// REMOVE_START | ||||||
assert.equal(res5, 'OK'); | ||||||
assert.deepEqual(res6, ["Deimos", "Ares", "Vanth"]); | ||||||
// REMOVE_END | ||||||
|
||||||
// STEP_START incr | ||||||
await client.set("total_crashes", 0); | ||||||
const res7 = await client.incr("total_crashes"); | ||||||
console.log(res7); // 1 | ||||||
const res8 = await client.incrBy("total_crashes", 10); | ||||||
console.log(res8); // 11 | ||||||
// STEP_END | ||||||
|
||||||
// REMOVE_START | ||||||
assert.equal(res7, 1); | ||||||
assert.equal(res8, 11); | ||||||
// REMOVE_END | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move line 67 to end. |
||||||
|
||||||
await client.quit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to match what's in the CLI example.