table of Contents
Redis data structure
redis is stored: key, value format of the data , wherein the key is a string, value there are five kinds of different data structures
1. String type String
2. Hash type hash: map format
3. List type List: linkedlist format (repeated elements allowed)
4. Set type set (repeated elements not allowed)
5. Sorted set type sortedset (repeated not allowed) Elements, and will be sorted automatically)
The value value is the value of the stored string type
key | type of data | form |
my_str | String type | username zhangsan |
my_hash | Hash type | name Li Si age 21 |
my_list | List type | 22 23 24 22 |
my_set | Collection type | 21 23 24 |
my_sortedset | Ordered collection type | 21 23 24 25 |
String type
Redis string data type related commands are used to manage redis string values
1. Store: set key value such as set name zhangsan (set name zhangsan can be set again)
2. Get: get key such as get username
3. Delete: del key such as del username
The above are more commonly used, if you want to learn more, click --> want to learn more
Hash type
Redis hash is a mapping table of string type field (field ) and value (value) , hash is especially suitable for storing objects
1. Store: hset key filed value
2. Get: hget key filed (this is to get the value of the specified file) hgetall key this is to get all the files
3. Delete: hdel key filed
this key is the hash name
Demo:
The above are more commonly used, if you want to learn more, click --> want to learn more
List type
The Redis list is a simple list of strings , sorted in the order of insertion . You can add an element to the head (left) or the tail (right) of the list
Add :
lpush key value : add the element to the left table of the list
rpush key value : add the element to the right table of the list to
get:
lrange key start end (index) ( starting on the left is positive, and starting on the right is -1 )
The range is [start,end]
delete :
lpop: delete from the left of the list and return the deleted value
rpop: delete from the right of the list and return the deleted value
Demo :
The above are more commonly used, if you want to learn more, click --> want to learn more
Collection type
Redis's Set is an unordered collection of String type . Set members are unique , which means that no duplicate data can appear in the set.
Storage: sadd key value
acquisition: smembers key acquisition of all elements in the collection
delete: srem key value delete an element in the collection
Demo:
The above are more commonly used, if you want to learn more, click --> want to learn more
Ordered collection type
Redis ordered collection is also a collection of string type elements like a collection , 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.
Add: zadd key score value
acquisition: zrange key start end
zrange key start end withscores bring the scores and
delete: zrem key value
Demo:
The above are more commonly used, if you want to learn more, click --> want to learn more
Common commands
1. keys *: query all keys
2. type key: get the type of value corresponding to the
key 3. del key: delete the value of the specified key
Demo: