-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Adds doctest examples for the hash tutorial #2821
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a011ff0
Create dt_hash.py
sav-norem 5abec75
Fixes some steps not showing
elena-kolevska 57ed0fe
Fixes instructions for doctests
elena-kolevska c9cd3ba
Making linter happy
elena-kolevska 8a1cbef
Format result as per Igor’s suggestion
elena-kolevska 87e5656
Change all the other outputs to Igor’s suggestion
elena-kolevska 5f2c180
make linter happy
elena-kolevska 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
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,91 @@ | ||
# EXAMPLE: hash_tutorial | ||
# HIDE_START | ||
import redis | ||
|
||
r = redis.Redis(decode_responses=True) | ||
# HIDE_END | ||
# STEP_START set_get_all | ||
res1 = r.hset( | ||
"bike:1", | ||
mapping={ | ||
"model": "Deimos", | ||
"brand": "Ergonom", | ||
"type": "Enduro bikes", | ||
"price": 4972, | ||
}, | ||
) | ||
print(res1) # 4 | ||
|
||
res2 = r.hget("bike:1", "model") | ||
print(res2) # 'Deimos' | ||
|
||
res3 = r.hget("bike:1", "price") | ||
print(res3) # '4972' | ||
|
||
res4 = r.hgetall("bike:1") | ||
print( | ||
res4 | ||
) # {'model': 'Deimos', 'brand': 'Ergonom', 'type': 'Enduro bikes', 'price': '4972'} | ||
|
||
# STEP_END | ||
|
||
# REMOVE_START | ||
assert res1 == 4 | ||
assert res2 == "Deimos" | ||
assert res3 == "4972" | ||
assert res4 == { | ||
"model": "Deimos", | ||
"brand": "Ergonom", | ||
"type": "Enduro bikes", | ||
"price": "4972", | ||
} | ||
# REMOVE_END | ||
|
||
# STEP_START hmget | ||
res5 = r.hmget("bike:1", ["model", "price"]) | ||
print(res5) # ['Deimos', '4972'] | ||
# STEP_END | ||
|
||
# REMOVE_START | ||
assert res5 == ["Deimos", "4972"] | ||
# REMOVE_END | ||
|
||
# STEP_START hincrby | ||
res6 = r.hincrby("bike:1", "price", 100) | ||
print(res6) # 5072 | ||
res7 = r.hincrby("bike:1", "price", -100) | ||
print(res7) # 4972 | ||
# STEP_END | ||
|
||
# REMOVE_START | ||
assert res6 == 5072 | ||
assert res7 == 4972 | ||
# REMOVE_END | ||
|
||
|
||
# STEP_START incrby_get_mget | ||
res11 = r.hincrby("bike:1:stats", "rides", 1) | ||
print(res11) # 1 | ||
res12 = r.hincrby("bike:1:stats", "rides", 1) | ||
print(res12) # 2 | ||
res13 = r.hincrby("bike:1:stats", "rides", 1) | ||
print(res13) # 3 | ||
res14 = r.hincrby("bike:1:stats", "crashes", 1) | ||
print(res14) # 1 | ||
res15 = r.hincrby("bike:1:stats", "owners", 1) | ||
print(res15) # 1 | ||
res16 = r.hget("bike:1:stats", "rides") | ||
print(res16) # 3 | ||
res17 = r.hmget("bike:1:stats", ["crashes", "owners"]) | ||
print(res17) # ['1', '1'] | ||
# STEP_END | ||
|
||
# REMOVE_START | ||
assert res11 == 1 | ||
assert res12 == 2 | ||
assert res13 == 3 | ||
assert res14 == 1 | ||
assert res15 == 1 | ||
assert res16 == "3" | ||
assert res17 == ["1", "1"] | ||
# 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.
Uh oh!
There was an error while loading. Please reload this page.