In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what data types are supported in Redis. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Redis supports five data types: string (string), hash (hash), list (list), set (collection) and zset (sorted set: ordered collection).
String (string)
String is the most basic type of redis, which you can understand as exactly the same type as Memcached, with a key corresponding to a value.
The string type is binary safe. It means that the string of redis can contain any data. Such as jpg images or serialized objects.
The string type is the most basic data type of Redis, and the value of the string type can store 512MB at most.
Common commands: set, get, decr, incr, mget, etc.
Note: a key can store 512MB at most.
Hash (hash)
Redis hash is a collection of key-value pairs (key= > value); it is a mapping table of field and value of type string, and hash is particularly suitable for storing objects.
Each hash can store 232-1 key-value pairs (over 4 billion).
Common commands: hget, hset, hgetall, etc.
Application scenario: store some structured data, such as the user's nickname, age, gender, points, etc., and store a user information object data.
List (list)
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.
The list type is often used for message queuing services to complete message exchange between multiple programs.
Common commands: lpush, rpush, lpop, rpop, lrange, etc.
Lists can store up to 232-1 elements (4294967295, each list can store more than 4 billion).
Set (collection)
The Set of Redis is an unordered collection of type string. Like lists, it is efficient to perform inserts and deletions and to determine whether an element exists. The biggest advantage of set is that it can perform intersection and difference set operation. The maximum number of elements that a Set can contain is 4294967295.
The collection is implemented through a hash table, so the complexity of adding, deleting, and finding is all O (1).
Application scenarios:
1. Make use of intersection to find common friends.
2. Using uniqueness, you can count all the independent IP of visiting the website.
3. When recommended by friends, you can find the intersection according to tag. If it is greater than a certain threshold (critical value), you can recommend it.
Common commands: sadd, spop, smembers, sunion, etc.
The maximum number of members in the collection is 4294967295 (each collection can store more than 4 billion members).
Zset (sorted set: ordered set)
Redis zset, like set, is a collection of elements of type string, and duplicate members are not allowed.
The difference is that each element is associated with a score of type double. Redis sorts the members of the collection from small to large by scores.
The members of the zset are unique, but the score can be repeated.
Sorted set is inserted in order, that is, automatic sorting.
Common commands: zadd, zrange, zrem, zcard, etc.
When you need an ordered and non-repeating list of collections, you can choose sorted set data structures.
Application examples:
(1) for example, to store the grades of the whole class, the collection value can be the student number of the students, and the score can be the grade.
(2) ranking application, listing topN users according to their scores, etc.
About which data types supported in Redis are shared here, I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.