Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The data types of Redis and the usage scenarios for each data type

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

People are very strange animals, and very simple questions are easy to ignore. When we use distributed cache Redis, one of the simplest questions is often ignored. What is the data type of Redis and the usage scenario of each data type?

Do you think this question is very basic? I think so, too. However, according to the survey experience, at least 80% of people can not answer this question.

Basically, a qualified programmer will use all five types.

1.String

There is nothing to say about this, the most conventional set/get operation, Value can be String or a number. Generally do some complex counting function of the cache.

2.Hash

Here Value stores structured objects, and it is convenient to manipulate one of the fields.

When I do single sign-on, I use this data structure to store user information, use CookieId as Key, and set 30 minutes as cache expiration time, which can well simulate the effect similar to Session.

3.List

Using the data structure of List, you can do a simple message queue function. Another is that you can use the lrange command to do Redis-based paging with excellent performance and a good user experience.

4.Set

Because Set stacks a collection of values that are not repeated. So you can do the global de-duplication function. Why not use the Set that comes with JVM to remove the weight?

Because our systems are generally deployed in clusters, it is troublesome to use the Set that comes with JVM. Is it too troublesome to do a global de-duplication and start a public service?

In addition, the use of intersection, union, subtraction and other operations, you can calculate common preferences, all preferences, their own unique preferences and other functions.

5.Sorted Set

Sorted Set has an extra weight parameter Score, and the elements in the collection can be arranged by Score.

Can do ranking application, take TOP N operation. Sorted Set can be used to do deferred tasks. The last application is to do a range search.

If you have any in-depth research on Redis, you are welcome to come to China to post for the cloud official forum and discuss it together. You can also go to Huawei Cloud help Center and take a look at our detailed operating instructions.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report