-
Notifications
You must be signed in to change notification settings - Fork 1.9k
DOC-2558 - Adds code examples for the sorted set tutorial #2634
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
Open
justincastilla
wants to merge
1
commit into
redis:emb-examples
Choose a base branch
from
justincastilla:DOC-2558
base: emb-examples
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// EXAMPLE: hash_tutorial | ||
// HIDE_START | ||
import assert from 'assert'; | ||
import { createClient } from 'redis'; | ||
|
||
const client = createClient(); | ||
await client.connect(); | ||
// HIDE_END | ||
//// STEP_START hSet_hGet_hGetAll | ||
const res1 = await client.hSet( | ||
'bike:1', | ||
{ | ||
'model': 'Deimos', | ||
'brand': 'Ergonom', | ||
'type': 'Enduro bikes', | ||
'price': 4972, | ||
}, | ||
) | ||
console.log(res1) // 4 | ||
|
||
const res2 = await client.hGet('bike:1', 'model') | ||
console.log(res2) // 'Deimos' | ||
|
||
const res3 = await client.hGet('bike:1', 'price') | ||
console.log(res3) // '4972' | ||
|
||
const res4 = await client.hGetAll('bike:1') | ||
console.log(res4) | ||
/* | ||
{ | ||
brand: 'Ergonom', | ||
model: 'Deimos', | ||
price: '4972', | ||
type: 'Enduro bikes' | ||
} | ||
*/ | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
assert.equal(res1, 4); | ||
assert.equal(res2, 'Deimos'); | ||
assert.equal(res3, '4972'); | ||
assert.deepEqual(res4, { | ||
model: 'Deimos', | ||
brand: 'Ergonom', | ||
type: 'Enduro bikes', | ||
price: '4972' | ||
}); | ||
// REMOVE_END | ||
|
||
// STEP_START hmGet | ||
const res5 = await client.hmGet('bike:1', ['model', 'price']) | ||
console.log(res5) // ['Deimos', '4972'] | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
assert.deepEqual(Object.values(res5), ['Deimos', '4972']) | ||
// REMOVE_END | ||
|
||
// STEP_START hIncrBy | ||
const res6 = await client.hIncrBy('bike:1', 'price', 100) | ||
console.log(res6) // 5072 | ||
const res7 = await client.hIncrBy('bike:1', 'price', -100) | ||
console.log(res7) // 4972 | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
assert.equal(res6, 5072) | ||
assert.equal(res7, 4972) | ||
// REMOVE_END | ||
|
||
|
||
// STEP_START hIncrBy_hGet_hMget | ||
const res11 = await client.hIncrBy('bike:1:stats', 'rides', 1) | ||
console.log(res11) // 1 | ||
const res12 = await client.hIncrBy('bike:1:stats', 'rides', 1) | ||
console.log(res12) // 2 | ||
const res13 = await client.hIncrBy('bike:1:stats', 'rides', 1) | ||
console.log(res13) // 3 | ||
const res14 = await client.hIncrBy('bike:1:stats', 'crashes', 1) | ||
console.log(res14) // 1 | ||
const res15 = await client.hIncrBy('bike:1:stats', 'owners', 1) | ||
console.log(res15) // 1 | ||
const res16 = await client.hGet('bike:1:stats', 'rides') | ||
console.log(res16) // 3 | ||
const res17 = await client.hmGet('bike:1:stats', ['crashes', 'owners']) | ||
console.log(res17) // ['1', '1'] | ||
// STEP_END | ||
|
||
// REMOVE_START | ||
assert.equal(res11, 1); | ||
assert.equal(res12, 2); | ||
assert.equal(res13, 3); | ||
assert.equal(res14, 1); | ||
assert.equal(res15, 1); | ||
assert.equal(res16, '3'); | ||
assert.deepEqual(res17, ['1', '1']); | ||
await client.quit(); | ||
// REMOVE_END |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.