In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 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 is the difference between set and hset in redis. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
When storing data in redis, when is it different from storing data in hset compared to set?
Set is a common way to store data in key-value mode, and you can set the expiration time. The time complexity is O (1). Without executing one more set, there will be one more key in the redis, and the hset is stored in the form of a hash hash table. The timeout can only be set on a large key, but not on a single filed. Many articles on Baidu say O (1), but the reference article I give below says that the time complexity is actually O (N) N is the number of filed on a single hash, so it is not suitable to store a large amount of filed on a single hash and consume more cpu if there is too much filed. But storing in a hash table at the same time saves memory.
So in the actual use process, we should use set to store a single large text unstructured data hset stores structured data, a hash stores a piece of data, a filed stores an attribute in a piece of data, and value is the corresponding value of the attribute.
For example, there is a table user in the database that contains four attributes of id,name,age,sex and has 400w pieces of data.
Id,name,age,sex
1, 1, Zhang San, 16 1
2, 2, Li Si, 22 1
3, 3, Wang Wu, 28pi 0
4, 4, Zhao Liu, 32 pm 1
...
If you want to cache the entire table in redis, use hash, and one piece of data, one hash, one hash, contains four filed.
Hset user_1 id 1 name Zhang San age 16 sex 1
Hset user_2 id 2 name Li Si age 16 sex 1
...
In this way, if the value of an attribute of the user changes, it can be modified individually.
For example, if Zhang San's age is changed to 30, you can use the command: hset user_1 age 30.
For example, if you want to cache the entire home page html, or if you want to cache the details of a product (generally speaking, the product details are rich text information in makdown syntax, or rich text information in html format), you can use set.
Or you can use set to store a large piece of hot data in an application.
About redis set and hset have any differences to share here, I hope the above content can be of some help to you, can 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.