English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Redis Ltrim Command
Redis Ltrim trims a list by keeping only the elements within the specified range, and deleting all elements outside the specified range. 1 Index 0 represents the first element of the list, with You can also use negative indices to represent the second element of the list, and so on. -1 represents the last element of the list, -2 represents the second-to-last element of the list, and so on.
The basic syntax of the redis Ltrim command is as follows:
redis 127.0.0.1:6379> LTRIM KEY_NAME START STOP
>= 1.0.0
Returns 'ok' when the command executes successfully.
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"