In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What are the types of redis lists? In order to give you a better understanding of the types of redis lists, the editor summarizes the following. Let's read on.
The Redis list is a simple list of strings sorted in the order in which they are inserted. You can add an element to the head (left) or tail (right) of the list.
A list can contain up to 232-1 elements (4294967295, each list has more than 4 billion elements).
{'numbers': [1, 2, 3, 4, 5, 6, 7 dagger 8]' letters': ['aura,' baked, 'caged,' dashed, 'estranged,' faded, 'grubbing
This is the list type, the elements in the list must be strings, and the data types cannot be nested.
All the operations of the list type are the list operations corresponding to key. (think about it, add, delete, insert, delete, pop up, cut, and python. I think redis should have them all.)
LPUSH key value [value...] # add elements to the left
Redis 127.0.0.1 1redis 6379 > lpush numbers 1 (integer) 1redis 127.0.0.1 1redis 6379 > lpush numbers 2 3 (integer) 3
RPUSH key value [value...] # add data to the right
LLEN key # gets the number of elements in the list
Redis 127.0.0.1 redis 6379 > llen numbers (integer) 3
LRANGE key sart stop # getting a list fragment is similar to the slicing function of python, except that the data returned when slicing contains stop location data
Redis 127.0.0.1 redis 6379 > lrange numbers 0-1 # get all the list data "3"2"1" redis 127.0.0.1 redis > lrange numbers 0 5 "3" 2 "1" 1 "redis 127.0.1" 3 "3" 2 "1"
LPOP key # pops up an element from the left
Redis 127.0.0.1 redis 6379 > lrange numbers 0-1 "3"2"1" redis 127.0.0.1 redis 6379 > lrange numbers 0-1 "2"1"
RPOP # pops up an element from the right on the same principle as above
LREM key count value
# Delete the specified value from the list
# count > 0 removes the value equal to value from the left side of the position of count
Redis 127.0.0.1 redis 6379 > lrem numbers 0-1 "4"3"2"1" redis 127.0.0.1 redis 6379 > lrem numbers 1 3 (integer) 1redis 127.0.0.1 lrem numbers 0-1 "4"2" 1 "
# count > 0 removes the value equal to value from the left side of the position of count
# count=0 deletes all elements with a value of value
LINDEX key index # gets the element value of the specified index
Redis 127.0.0.1nil 6379 > lrange numbers 0-1 "4" 1 "redis 127.0.0.1 redis 6379 > lindex numbers 3 (nil) # No return nilredis 127.0.0.1 nil 6379 > lindex numbers 1" 1 "redis 127.0.0.1nil 6379 > lindex numbers 0" 4 "
LSET key index value # sets the value of the specified position, and it must be noted that it replaces the original position, unless there is no value for that position.
Redis 127.0.0.1 2OKredis 6379 > lrange numbers 0-1 "4" 1 "1" redis 127.0.0.1 redis 6379 > lset numbers 1 2OKredis 127.0.1 redis 6379 > lset numbers 1 3OKredis 127.0.1 redis 6379 > lrange numbers 0-1 "4"3"
NOTE: set to error out of range
Redis 127.0.0.1 error 6379 > lset numbers 2 3 (error) ERR index out of range
LTRIM key start end # cuts the original list, and elements outside the specified range will be deleted
Redis 127.0.0.1 redis 6379 > redis 0-1 "4"3"2"1" redis 127.0.1 redis 6379 > ltrim numbers 1 2OKredis 127.0.1 2OKredis 6379 > lrange numbers 0-1 "3"2"
LINSERT key before | after pivot value # inserts a value into the list. You can see the name. Insert it before or after the pivot.
Redis 127.0.0.1 "3" 2 "lrange numbers 0-1" 3 "2" redis 127.0.1 0.1 linsert numbers before 6379 > linsert numbers after 2 1 (integer) 3redis 127.0.0.1 redis 6379 > lrange numbers 0-1 "3" 2 "1" redis 127.0.1 "3" 2 "1" redis 127.0.1 "3" 2 "1" redis 127.0.1 linsert numbers before 3 4 (integer) 4redis 127.0.1 linsert numbers before 6379 > lrange numbers 0-1 "4" 3 "" 2 "1"
RPOPLPUSH source destination # pops up an element from the right side of source and adds it to the left side of destination
Redis > LRANGE alpha 0-1 # View all elements "a"b"c"d" redis > RPOPLPUSH alpha reciver # execute RPOPLPUSH once to see "d" redis > LRANGE alpha 0-1 "a" b "" c "redis > LRANGE reciver 0-1" d "
This is all about what the redis list types have. In addition, during the Spring Festival this year, three new "cloud database" products and services were launched: cloud database MySQL, cloud database Redis and cloud database Memcached. Cloud database Redis is a ready-to-use, stable and reliable high-performance data caching service, which supports "master-slave hot backup" and provides "automatic disaster recovery switching, instance monitoring, online capacity expansion" and other features.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.