Redis Ltrim Command

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.