Redis Ltrim command
Redis Ltrim a list of trim (trim), that is, make a list of only the retention interval specified element, the element is not specified within the range will be deleted.
Subscript 0 indicates the first element in the list to the second element 1 represents a list, and so on. You can also use a negative index to -1 means the last element of the list, -2 represents the second to last element of a list, and so on.
grammar
redis Ltrim basic command syntax is as follows:
redis 127.0.0.1:6379> LTRIM KEY_NAME START STOP
Available versions
> = 1.0.0
return value
When the command is executed successfully returned ok.
Examples
redis 127.0.0.1:6379> RPUSH mylist "hello" (integer) 1 redis 127.0.0.1:6379> RPUSH mylist "hello" (integer) 2 redis 127.0.0.1:6379> RPUSH mylist "foo" (integer) 3 redis 127.0.0.1:6379> RPUSH mylist "bar" (integer) 4 redis 127.0.0.1:6379> LTRIM mylist 1 -1 OK redis 127.0.0.1:6379> LRANGE mylist 0 -1 1) "hello" 2) "foo" 3) "bar"