Interview Series 13 redis what are data types

(1)string

 

This is the most basic type, and nothing to say, is an ordinary set and get, do simple kv cache

 

(2)hash

 

This is a structure similar to the map, this is to be generally structured data, such as an object (if the object is not nested other objects) to cache redis, and then each read and write the cache, they can on the operation hash in a field.

 

key=150

 

value={

  “id”: 150,

  "Name": "zhangsan",

  “age”: 20

}

 

Hash class data structure is mainly used to store a number of objects, some simple objects to be cached, when the subsequent operations, you can directly modify only the value of a field in the object

 

value={

  “id”: 150,

  "Name": "zhangsan",

  “age”: 21

}

 

 

(3)list

 

Ordered list, which can play a lot of tricks

 

Weibo, a big fan of v, you can go on redis cached list format

 

a big key = v

 

value = [zhangsan, lisi, wangwu]

 

For example, by storing a list of some type of list data structure, similar to the fan list, review the list of things like

 

For example, by lrange command, is to start reading the number of elements from an element, you can implement paging list based on a query, this is a great feature, based on simple, high-performance redis page, you can do a similar kind of microblogging continue to drop down paging things, high performance, go from page to page

 

Example, can put forward a simple message queue, into the dislike list head, tail, where it comes out from the list

 

(4)set

 

Unordered collection, automatic de-duplication

 

Set directly on the system need to re-thrown to the data, automatically give weight to, and if you need some quick global data de-duplication, of course, you can go heavy on jvm memory of HashSet, but if you deploy a system on multiple machines?

 

Redis have to be based on the overall weight set to go

 

Can be set to play an intersection, union, difference-based operations, such as the intersection of it, you can put two people in a whole list of fans intersection, take a look at two people who in common is that? Right

 

V The two large fans are placed in set two, do the intersection of two set

 

(5)sorted set

 

Sort of set, but can be re-sorted to write into the time to a fraction, according to scores automatically sort, this can play a lot of tricks, the biggest feature is to have a score can be custom collations

 

For example, if you want to sort the data according to the time when, you can write into it by a certain time as the score, people automatically give you sort by time

 

Ranking: each user and its corresponding fraction of what is written inside, zadd board score username, then zrevrange board 0 99, the user can get the top 100; zrank board username, the user can see the charts in the ranking

 

zadd board 85 zhangsan

zadd board 72 wangwu

zadd board 96 lisi

zadd board 62 zhaoliu

 

96 lysis

85 zhangsan

72 wangwu

62 zhaoliu

 

zrevrange board 0 3

 

Users get top 3

 

96 lysis

85 zhangsan

72 wangwu

 

zrank board zhaoliu

 

4

Guess you like

Origin www.cnblogs.com/xiufengchen/p/11258935.html