Redis Ltrim trims a list (trim), which means that the list retains only the elements within the specified interval, and the elements that are not within the specified range are deleted.
Subscript 0 Represents the first element of the list, 1 represents the second element of the list, and so on. You can also use a negative subscript to 1 for the last element of the list, 2 to represent the penultimate element of the list, and so on.
Grammar
The basic syntax for the Redis Ltrim command is as follows:
Redis 127.0.0.1:6379> LTRIM key_name START STOP
Available versions
>= 1.0.0
return value
Returns OK when the command executes successfully.
Instance
Redis 127.0.0.1:6379> rpush mylist "Hello" (integer) 1redis 127.0.0.1:6379> rpush mylist "Hello" (integer) 2redis 127 .0.0.1:6379> rpush mylist "foo" (integer) 3redis 127.0.0.1:6379> rpush mylist "Bar" (integer) 4redis 127.0.0.1:6379& Gt LTRIM mylist 1-1okredis 127.0.0.1:6379> lrange mylist 0-11) "Hello" 2) "foo" 3) "Bar"
Redis Ltrim Command