In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What are the redis data types? I believe there are many people do not understand, today, in order to let you know more about the redis data type, so give you a summary of the following content, let's look down together.
Redis has the following main data types:
String
Hash
List
Set
Sorted set
String
This is the simplest type, which is plain set and get, which do simple KV caching.
Set college szu
Hash
This is a structure similar to map, which generally allows you to cache structured data, such as an object (provided that the object does not nest other objects) in the redis, and then manipulate a field in the hash every time you read or write the cache.
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 with a lot of tricks.
For example, you can use list to store some column phenotypic data structures, such as fan lists, comment lists of articles, and so on.
For example, you can use the lrange command to read elements in a closed interval, and you can achieve paging query based on list, which is a great function. Based on redis, you can achieve simple high-performance paging, and you can do things like Weibo that drop down and keep paging. With high performance, you can go page by page.
The start position of # 0, the end position of-1, and the end position of-1 indicates the last position of the list, that is, view all.
Lrange mylist 0-1
For example, you can set up a simple message queue, go in from the list head and get it out of the list tail.
Lpush mylist 1lpush mylist 2lpush mylist 3 4 5# 1rpop mylist
Set
Set is an unordered set, which is automatically deduplicated.
Throw the data that needs to be deduplicated in the system directly based on set, and it will be deduplicated automatically. If you need to quickly remove the weight of some data globally, you can also do it based on the HashSet in jvm memory, but what if your system is deployed on multiple machines? Global set deduplication must be done based on redis.
You can play the operations of intersection, union and difference based on set, such as intersection. You can intersect the fan list of two people and see who their common friends are. Right.
Put the fans of the two big Vs in the two set, and make the intersection of the two set.
#-operate a set-# add element sadd mySet "View all elements smembers mySet# to determine whether it contains a value sismember mySet" Delete some / some elements srem mySet 1srem mySet 2 "View the number of elements scard mySet# randomly delete an element spop mySet#- operation multiple set-# will be an set element Move to another setsmove yourSet mySet solution to find the intersection of two set sinter yourSet mySet# to find the union of two set sunion yourSet mySet# to find the element sdiff yourSet mySet in yourSet but not in mySet
Sorted set
Sorted set is a sorted set, which can be sorted when it is deduplicated. When written in, it is given a score, and it is automatically sorted according to the score.
Zadd board 85 zhangsanzadd board 72 lisizadd board 96 wangwuzadd board 63 zhaoliu# get the top three users (the default is ascending order, so you need to change rev to descending order) zrevrange board 0 users get a user's ranking zrank board zhaoliu
These are the details of the redis data type, please pay more attention to other related articles!
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.