[Fun with Redis Interview Lecture 1] Redis data structure and shorthand for commonly used commands

Redis is a key-value database. The type of key can only be String, but the data type of value is richer, mainly including five types:

  • String

  • Hash

  • List

  • Set

  • Sorted Set

1. String

grammar

SET KEY_NAME VALUE

The string type is binary safe. This means that the redis string can contain any data. Such as jpg images or serialized objects. The string type is the most basic data type of Redis, and a key can store up to 512MB.

2. Hash

grammar

HSET KEY_NAME FIELD VALUE

Redis hash is a collection of key-value (key=>value) pairs. Redis hash is a mapping table between field and value of string type, and hash is particularly suitable for storing objects.

3. List

grammar

//在 key 对应 list 的头部添加字符串元素
LPUSH KEY_NAME VALUE1.. VALUEN//在 key 对应 list 的尾部添加字符串元素
RPUSH KEY_NAME VALUE1..VALUEN//对应 list 中删除 count 个和 value 相同的元素
LREM KEY_NAME COUNT VALUE//返回 key 对应 list 的长度
LLEN KEY_NAME

Redis lists are simple lists of strings, sorted in the order of insertion. You can add an element to the head (left) or tail (right) of the list

4. Set collection

grammar

SADD KEY_NAME VALUE1...VALUEn

Redis Set is an unordered collection of string type. The collection is implemented through a hash table, so the complexity of adding, deleting, and searching is O(1).

5. Sorted Set ordered set

grammar

ZADD KEY_NAME SCORE1 VALUE1.. SCOREN VALUEN

Redis zset, like set, is also a collection of string type elements, and duplicate members are not allowed. The difference is that each element is associated with a double type score.

Redis uses scores to sort the members of the set from small to large.

The members of zset are unique, but the score (score) can be repeated.

6. Redis common command reference

For more command syntax, please refer to the official website manual:

https://www.redis.net.cn/order/

 

Don’t you think it’s too simple? It’s okay. This is a complete series. Collect it and continue to read one~

- END -

 

Laughter architects are not too bad in technology. Scan the QR code on WeChat or search the subscription number "Laughing Architects" to pay attention, and more technical dry goods will be posted as soon as possible!

Finally, as a bonus, the laughable architect has collected a lot of genuine e-books on related technologies. After paying attention to the public account, reply to the number 666 to get it for free.

 

 


Guess you like

Origin blog.csdn.net/guoguo527/article/details/108805496