File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import redis
2+
3+ # init the redis obj
4+ r = redis .Redis (host = "127.0.0.1" ,
5+ port = 6379 ,
6+ db = 0 ,
7+ decode_responses = True )
8+
9+
10+ # add some elements into the list
11+ r .lpush ("books" , * ("clean code" , "Code Complete" , "Peopleware" ))
12+
13+
14+ # get item at index
15+ print (r .lindex ("books" , 2 ))
16+
17+
18+ # Get the length of the list
19+ respllen = r .llen (name = "books" )
20+ print ("length of list books is " , r .llen ("books" ))
21+
22+
23+ # Get a subset of the list items including start & end
24+ # index starts at 0
25+ # even if index is out of bound, returns till last element.
26+ # Can also use negitive numbers, same like python slicing
27+ resplrange = r .lrange (name = "books" , start = 0 , end = - 2 )
28+ print (resplrange )
29+
30+
31+ # LPOP returns first element while RPOP returns last element
32+ print (r .lpop (name = 'books' ))
33+ print (r .rpop (name = 'books' ))
34+
35+
36+ r .flushdb ()
You can’t perform that action at this time.
0 commit comments