File tree Expand file tree Collapse file tree 2 files changed +40
-24
lines changed
content/develop/clients/redis-py
local_examples/client-specific/redis-py Expand file tree Collapse file tree 2 files changed +40
-24
lines changed Original file line number Diff line number Diff line change @@ -54,39 +54,23 @@ You can try this code out in a [Jupyter notebook on Binder](https://redis.io/bin
5454
5555{{< /note >}}
5656
57- ``` python
58- r = redis.Redis(host = ' localhost' , port = 6379 , decode_responses = True )
59- ```
57+ {{< clients-example set="landing" step="connect" lang_filter="Python" >}}
58+ {{< /clients-example >}}
6059
6160Store and retrieve a simple string.
6261
63- ``` python
64- r.set(' foo' , ' bar' )
65- # True
66- r.get(' foo' )
67- # bar
68- ```
62+ {{< clients-example set="landing" step="set_get_string" lang_filter="Python" >}}
63+ {{< /clients-example >}}
6964
7065Store and retrieve a dict.
7166
72- ``` python
73- r.hset(' user-session:123' , mapping = {
74- ' name' : ' John' ,
75- " surname" : ' Smith' ,
76- " company" : ' Redis' ,
77- " age" : 29
78- })
79- # True
80-
81- r.hgetall(' user-session:123' )
82- # {'surname': 'Smith', 'name': 'John', 'company': 'Redis', 'age': '29'}
83- ```
67+ {{< clients-example set="landing" step="hash_operations" lang_filter="Python" >}}
68+ {{< /clients-example >}}
8469
8570Close the connection when you're done.
8671
87- ``` python
88- r.close()
89- ```
72+ {{< clients-example set="landing" step="close" lang_filter="Python" >}}
73+ {{< /clients-example >}}
9074
9175## More information
9276
Original file line number Diff line number Diff line change 1+ # EXAMPLE: landing
2+ # REMOVE_START
3+ import redis
4+ # REMOVE_END
5+
6+ # STEP_START connect
7+ r = redis .Redis (host = 'localhost' , port = 6379 , decode_responses = True )
8+ # STEP_END
9+
10+ # STEP_START set_get_string
11+ r .set ('foo' , 'bar' )
12+ # True
13+ r .get ('foo' )
14+ # bar
15+ # STEP_END
16+
17+ # STEP_START hash_operations
18+ r .hset ('user-session:123' , mapping = {
19+ 'name' : 'John' ,
20+ "surname" : 'Smith' ,
21+ "company" : 'Redis' ,
22+ "age" : 29
23+ })
24+ # True
25+
26+ r .hgetall ('user-session:123' )
27+ # {'surname': 'Smith', 'name': 'John', 'company': 'Redis', 'age': '29'}
28+ # STEP_END
29+
30+ # STEP_START close
31+ r .close ()
32+ # STEP_END
You can’t perform that action at this time.
0 commit comments