Redis database (list type)
List is a linked list structure. The main function is to push, pop, get all values in a range, etc. In the operation, the key can be understood as the name of the linked list.
In Redis, the list type is actually a string-type two-way linked list. We can use the push and pop commands to add and delete elements from the head or tail of the linked list, in this way, the list can be both a stack and a queue.
List common operations:
(1) lpush and rpush
Lpush: adds a string element to the header of the list corresponding to the key. For example, lpush list Hello
Rpush indicates adding a string element to the end of the list corresponding to the key. Example: rpush list World
(2) lpop and rpop
Lpop deletes an element from the list header and returns the element.
Rpop deletes an element from the list header and returns the element.
(3) lrange
Extracts elements within the specified range. For example, lrange list 0-1, 0 is the subscript of the first element, and-1 is the subscript of the last element.
(4) linsert
Add a string before or after a specific position of the list corresponding to the key, for example:
Linsert list before Hello Redis indicates that an element Redis is inserted before "Hello" in the list linked list.
(5) lset
Set the value of the element specified in the list object. For example, lset list 1 Database means to replace the element marked as 1 in the list
Database.
(6) lrem
Delete n elements with the same value from the list corresponding to the key. If n <0 indicates that the elements are deleted from the end, n = 0 indicates that all elements are deleted.
Example: lrem list 1 Hello
(7) ltrim
Retain data within the specified key range. For example, ltrim list 1-1 is equivalent to retaining only the values of the elements starting from 1 to the end of the following table.
(8) rpoplpush
Remove the element from the end of the first list and add it to the header of the second list. For example:
(9) lindex
Returns the index position element in the list named key. For example, lindex list 1 returns the element marked as 1 in the list.
(10) llen
Returns the length of the list corresponding to the key.
Install and test Redis in Ubuntu 14.04
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: