Tag: New str means IDT intercepts 16px use img alt
The Redis list is a doubly linked list that can be used either as a stack or as a queue. Fortunately, the university has learned the data structure, but also the impression.
Stack: Advanced out, queue: FIFO
Redis Linked list operations:
Application Scenario Learning list link list: To obtain the latest 10 logged-in user information, if using sql: SELECT * from the user order by logintime desc limit 10; But the amount of data is large, this SQL down, the table all the data to be affected, the load on the database is relatively high, the need for the key field (ID or logintime) to set the index, too much set index is more expensive system resources.
Now with the Redis list: only 5 data is kept in the list, and an old data is deleted each time a new data is added. Each time can be directly from the linked list to obtain the required data, greatly saving all aspects of resources.
1. Start the Redis operating terminal and switch to the second database, which is empty:
,
2,Lpush operation: execute command Lpush (L is the left shorthand) command to add 5 data to the list, the list named Newlogin, indicating the newly logged on user, you can use the type Newlogin To see the type of Newlogin.
Now Redis's second database has a key is Newlogin list, which in turn saved Xiaoming, Jack, Jim, Zhangsan, Lisi five data.
3,Rpop operation: now to add a new data, delete a piece of data from the tail of the list, add a Xiaoli, and execute Rpop (R is shorthand for right) to remove the first added data (xiaoming) from the tail:
4,Llen, lrange operation:llen Newlogin Returns the length of the list. Lrange Newlogin 0 4 Returns the element of the list corresponding to the range, and returns all elements if the maximum subscript exceeds the length of the list.
Rpush is the addition of an element from the tail, Lpop is an element removed from the head, Rpush and Lpop are used together; Lpush and Rpop are used together.
5,ltrim action: Intercepts a subset of the elements in the list:
The Redis list