Five common data structures in redis-Hash scenario

 

 

 

 

 

Here is a question, what if you want to put all the millions of data in the entire table into redis? You can use segmentation, such as taking a modulo by id, making 100 userkeys, (segment keys) each key stores thousands of data.

 

 


127.0.0.1:6379> hset cart:1002 10088 1
(integer) 1
127.0.0.1:6379> hset cart:1002 10089 1
(integer) 1
127.0.0.1:6379> hlen cart:1002
(integer) 2
 two products

 

 

 

 

If you use the hash structure, because only the key is hashed, all the generated data may fall on one server. Of course, if the key itself is segmented, it will be fine. For example, the following adds multiple items to the shopping cart (cart:1002)

 

   At this time, if the above distributed is used, when the key is hashed, all data will only fall on a certain service.

 

 

Guess you like

Origin blog.csdn.net/liuming690452074/article/details/113799103