In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what are the main data types of redis". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "what are the main data types of redis".
Redis has the following data types:
string
hash
list
set
sorted set
string
This is the simplest type, that is, ordinary set and get, do simple KV cache.
set college szuhash
This is a structure similar to map, which generally allows structured data, such as an object (provided that this object is not nested with other objects), to be cached in redis, and then each time the cache is read or written, a field in hash can be manipulated.
hset person name bingohset person age 20hset person id 1hget person nameperson = {
"name": "bingo",
"age": 20,
"id": 1
}list
List is an ordered list, which can be played a lot of tricks.
For example, you can store some list-type data structures through lists, such as fan lists, comment lists of articles, and so on.
For example, you can read elements in a closed interval through the lrange command, you can implement paging queries based on list, this is a great function, simple high-performance paging based on redis, you can do things like microblogging that pull down pages continuously, high performance, go one page at a time.
# 0 start position,-1 end position, when the end position is-1, it indicates the last position of the list, i.e. view all.
lrange mylist 0 -1
For example, you can make a simple message queue, enter it from the list head and get it from the list tail.
lpush mylist 1lpush mylist 2lpush mylist 3 4 5
# 1
rpop mylistset
Set is an unordered set, automatically deduplicated.
If you need to quickly de-duplicate some data globally, you can certainly de-duplicate it based on the HashSet in jvm memory, but what if your system is deployed on multiple machines? We need to do global set de-duplication based on redis.
You can play intersection, union, difference set operations based on set, such as intersection bar, you can put two people's fan lists into an intersection to see who their common friends are? right?
Put the fans of both big V's in two sets and intersect the two sets.
#-------
#Add elements
sadd mySet 1
See all elements
smembers mySet
#Determine if it contains a value
sismember mySet 3
#Remove some element
srem mySet 1srem mySet 2 4
#Check the number of elements
scard mySet
#Delete an element randomly
spop mySet
#-------Operating multiple sets-----
Move elements from one set to another
smove yourSet mySet 2
#Find the intersection of two sets
sinter yourSet mySet
Find the union of two sets
sunion yourSet mySet
Find elements in yourSet that are not in mySet
sdiff yourSet mySetsorted set
Sorted set is a sorted set. It can be sorted without duplication. When it is written, it gives a score and automatically sorts according to the score.
zadd board 85 zhangsanzadd board 72 lisizadd board 96 wangwuzadd board 63 zhaoliu
#Get the top three users (default is ascending, so rev needs to be changed to descending)
zrevrange board 0 3
#Get a user's ranking
zrank board zhaoliu The above is "What are the main data types of redis" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
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.