Sunday 12 April 2015

LTRIM key start stop

Syntax
LTRIM key start stop
    Trim the list, so that it will contain only the specified range of elements specified.

127.0.0.1:6379> lpush ids 1 2 3 4 5 6 7 8 9 10 11 12 13 
(integer) 13 
127.0.0.1:6379> lrange ids 0 13 
 1) "13" 
 2) "12" 
 3) "11" 
 4) "10" 
 5) "9" 
 6) "8" 
 7) "7" 
 8) "6" 
 9) "5" 
10) "4" 
11) "3" 
12) "2" 
13) "1" 
127.0.0.1:6379> ltrim ids 0 5 
OK 
127.0.0.1:6379> lrange ids 0 13 
1) "13" 
2) "12" 
3) "11" 
4) "10" 
5) "9" 
6) "8" 


you can use -ve numbers also for start and stop, -1 is the last element of the list, -2 the penultimate element and so on.

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment