Sunday 5 April 2015

Redis list type


List is a sequence of ordered elements, for example 10, 5, 16, 20, 19 is a list. Redis lists are implemented as linked lists. Since lists in redis are implemented as linked list, adding elements to head/ tail of the list is faster, but accessing element using index is slow.

hk@hk-Inspiron-N5010:~$ redis-cli 
127.0.0.1:6379> lpush hobbies cricket 
(integer) 1 
127.0.0.1:6379> lpush hobbies "waching movies" 
(integer) 2 
127.0.0.1:6379> lpush hobbies "Writing blogs" 
(integer) 3 
127.0.0.1:6379> lrange hobbies 0 5 
1) "Writing blogs" 
2) "waching movies" 
3) "cricket" 
127.0.0.1:6379> 
 

lpush” command insert value to the head of the list and reurns the length of the list after the push operations.

lrange key start stop
lrange” command returns the range of elements from given set. The offsets start and stop are zero-based indexes, with 0 being the first element of the list, 1 being the next element and so on.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment