-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC-4423: add TCEs for various command pages (#3476)
Co-authored-by: Vladyslav Vildanov <[email protected]>
- Loading branch information
1 parent
fab31b4
commit afabed6
Showing
5 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,36 @@ | ||
# EXAMPLE: cmds_cnxmgmt | ||
# HIDE_START | ||
import redis | ||
|
||
r = redis.Redis(decode_responses=True) | ||
# HIDE_END | ||
|
||
# STEP_START auth1 | ||
# REMOVE_START | ||
r.config_set("requirepass", "temp_pass") | ||
# REMOVE_END | ||
res1 = r.auth(password="temp_pass") | ||
print(res1) # >>> True | ||
|
||
res2 = r.auth(password="temp_pass", username="default") | ||
print(res2) # >>> True | ||
|
||
# REMOVE_START | ||
assert res1 == True | ||
assert res2 == True | ||
r.config_set("requirepass", "") | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START auth2 | ||
# REMOVE_START | ||
r.acl_setuser("test-user", enabled=True, passwords=["+strong_password"], commands=["+acl"]) | ||
# REMOVE_END | ||
res = r.auth(username="test-user", password="strong_password") | ||
print(res) # >>> True | ||
|
||
# REMOVE_START | ||
assert res == True | ||
r.acl_deluser("test-user") | ||
# REMOVE_END | ||
# STEP_END |
This file contains 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 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,123 @@ | ||
# EXAMPLE: cmds_list | ||
# HIDE_START | ||
import redis | ||
|
||
r = redis.Redis(decode_responses=True) | ||
# HIDE_END | ||
|
||
# STEP_START lpush | ||
res1 = r.lpush("mylist", "world") | ||
print(res1) # >>> 1 | ||
|
||
res2 = r.lpush("mylist", "hello") | ||
print(res2) # >>> 2 | ||
|
||
res3 = r.lrange("mylist", 0, -1) | ||
print(res3) # >>> [ "hello", "world" ] | ||
|
||
# REMOVE_START | ||
assert res3 == [ "hello", "world" ] | ||
r.delete("mylist") | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START lrange | ||
res4 = r.rpush("mylist", "one"); | ||
print(res4) # >>> 1 | ||
|
||
res5 = r.rpush("mylist", "two") | ||
print(res5) # >>> 2 | ||
|
||
res6 = r.rpush("mylist", "three") | ||
print(res6) # >>> 3 | ||
|
||
res7 = r.lrange('mylist', 0, 0) | ||
print(res7) # >>> [ 'one' ] | ||
|
||
res8 = r.lrange('mylist', -3, 2) | ||
print(res8) # >>> [ 'one', 'two', 'three' ] | ||
|
||
res9 = r.lrange('mylist', -100, 100) | ||
print(res9) # >>> [ 'one', 'two', 'three' ] | ||
|
||
res10 = r.lrange('mylist', 5, 10) | ||
print(res10) # >>> [] | ||
|
||
# REMOVE_START | ||
assert res7 == [ 'one' ] | ||
assert res8 == [ 'one', 'two', 'three' ] | ||
assert res9 == [ 'one', 'two', 'three' ] | ||
assert res10 == [] | ||
r.delete('mylist') | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START llen | ||
res11 = r.lpush("mylist", "World") | ||
print(res11) # >>> 1 | ||
|
||
res12 = r.lpush("mylist", "Hello") | ||
print(res12) # >>> 2 | ||
|
||
res13 = r.llen("mylist") | ||
print(res13) # >>> 2 | ||
|
||
# REMOVE_START | ||
assert res13 == 2 | ||
r.delete("mylist") | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START rpush | ||
res14 = r.rpush("mylist", "hello") | ||
print(res14) # >>> 1 | ||
|
||
res15 = r.rpush("mylist", "world") | ||
print(res15) # >>> 2 | ||
|
||
res16 = r.lrange("mylist", 0, -1) | ||
print(res16) # >>> [ "hello", "world" ] | ||
|
||
# REMOVE_START | ||
assert res16 == [ "hello", "world" ] | ||
r.delete("mylist") | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START lpop | ||
res17 = r.rpush("mylist", *["one", "two", "three", "four", "five"]) | ||
print(res17) # >>> 5 | ||
|
||
res18 = r.lpop("mylist") | ||
print(res18) # >>> "one" | ||
|
||
res19 = r.lpop("mylist", 2) | ||
print(res19) # >>> ['two', 'three'] | ||
|
||
res17 = r.lrange("mylist", 0, -1) | ||
print(res17) # >>> [ "four", "five" ] | ||
|
||
# REMOVE_START | ||
assert res17 == [ "four", "five" ] | ||
r.delete("mylist") | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START rpop | ||
res18 = r.rpush("mylist", *["one", "two", "three", "four", "five"]) | ||
print(res18) # >>> 5 | ||
|
||
res19 = r.rpop("mylist") | ||
print(res19) # >>> "five" | ||
|
||
res20 = r.rpop("mylist", 2) | ||
print(res20) # >>> ['four', 'three'] | ||
|
||
res21 = r.lrange("mylist", 0, -1) | ||
print(res21) # >>> [ "one", "two" ] | ||
|
||
# REMOVE_START | ||
assert res21 == [ "one", "two" ] | ||
r.delete("mylist") | ||
# REMOVE_END | ||
# STEP_END |
This file contains 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,30 @@ | ||
# EXAMPLE: cmds_servermgmt | ||
# HIDE_START | ||
import redis | ||
|
||
r = redis.Redis(decode_responses=True) | ||
# HIDE_END | ||
|
||
# STEP_START flushall | ||
# REMOVE_START | ||
r.set("foo", "1") | ||
r.set("bar", "2") | ||
r.set("baz", "3") | ||
# REMOVE_END | ||
res1 = r.flushall(asynchronous=False) | ||
print(res1) # >>> True | ||
|
||
res2 = r.keys() | ||
print(res2) # >>> [] | ||
|
||
# REMOVE_START | ||
assert res1 == True | ||
assert res2 == [] | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START info | ||
res3 = r.info() | ||
print(res3) | ||
# >>> {'redis_version': '7.4.0', 'redis_git_sha1': 'c9d29f6a',...} | ||
# STEP_END |
This file contains 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,35 @@ | ||
# EXAMPLE: cmds_set | ||
# HIDE_START | ||
import redis | ||
|
||
r = redis.Redis(decode_responses=True) | ||
# HIDE_END | ||
|
||
# STEP_START sadd | ||
res1 = r.sadd("myset", "Hello", "World") | ||
print(res1) # >>> 2 | ||
|
||
res2 = r.sadd("myset", "World") | ||
print(res2) # >>> 0 | ||
|
||
res3 = r.smembers("myset") | ||
print(res3) # >>> {'Hello', 'World'} | ||
|
||
# REMOVE_START | ||
assert res3 == {'Hello', 'World'} | ||
r.delete('myset') | ||
# REMOVE_END | ||
# STEP_END | ||
|
||
# STEP_START smembers | ||
res4 = r.sadd("myset", "Hello", "World") | ||
print(res4) # >>> 2 | ||
|
||
res5 = r.smembers("myset") | ||
print(res5) # >>> {'Hello', 'World'} | ||
|
||
# REMOVE_START | ||
assert res5 == {'Hello', 'World'} | ||
r.delete('myset') | ||
# REMOVE_END | ||
# STEP_END |