Redis Notes Getting Started (1)

1 Getting Started with Redis

1.1 Redis download and installation

Please move to another blog post Redis download, installation, configuration

Reference document: Redis Chinese Network

1.2 Introduction to Redis

Redis is a database 存储中间件based on 内存the key-value structure, also known as a structured NoSql (non-relational) database.

Key-value structure storage:insert image description here

1.3 Redis features

  • Based on memory storage , high read and write performance
  • Suitable for storing hot data (hot commodities, information, news)
  • Widely used, developed in C language, the number of queries per second can reach 100,000+ QPS

2 Redis data types

2.1 key is a string type

key is a string type

2.2 value in key-value structure data

data structure translate explain
string string Ordinary strings, the simplest data type
hash hash Hashing, similar to the HashMap structure in Java
list the list Sort by insertion order, repeatable, similar to LinkedList in Java
set gather Unordered collection, no repetition, similar to HashSet in Java
sorted set / zset ordered set Each element in the collection is associated with a score (score), sorted in ascending order according to the score, without duplication

2.3 Characteristics of various data types

insert image description here

3 Redis common commands

3.1 Common operation commands for strings

Order illustrate
SET key value Set the value of the specified key
GET key Get the value of the specified key
SETEX key seconds value Set the value of the specified key and set the expiration time of the key to seconds seconds
SETNXkey value Only set the value of the key if the key does not exist

3.2 Hash common operation commands

Order illustrate
HSET key field value Set the value of the field field in the hash table key to value
`HGET`` key field Get the value stored in the specified field in the hash table
HDEL key field Delete the specified field stored in the hash table
HKEYS key Get all fields in the hash table
HVALSkey Get all values ​​in the hash table

insert image description here

3.3 List common operation commands

Order illustrate
LPUSH key value1 [value2] Insert one or more values ​​at the head of the list
LRANGE key start stop Get the elements in the specified range of the list
RPOPkey Remove and get the last element of the list
LLENkey get list length
BRPOP key1 [key2 ] timeout Move out and get the last element of the list, if there is no element in the list, the list will be blocked until the wait times out or a pop-up element is found

insert image description here

3.4 Collect common operation commands

Order illustrate
SADD key member1 [member2] Add one or more members to the collection
SMEMBERSkey Returns all members of the set
SCARDkey Get the number of members of a collection
SINTER key1 [key2] Returns the intersection of all sets given
SUNIONkey1 [key2] Returns the union of all the given collections
SREMkey member1 [member2] remove one or more members from the set

insert image description here

3.5 Common operation commands for ordered sets

Order illustrate
ZADD key score1 member1 [score2 member2] Adds one or more members to a sorted set
ZRANGE key start stop [WITHSCORES] Returns the members in the specified range in the sorted set through the index range
ZINCRBY key increment member Adds the increment to the score of the specified member in the sorted set
ZREM key member [member …] removes one or more members from a sorted set

insert image description here

3.6 Commonly used general commands

Order illustrate example
KEYS pattern Find all keys matching the given pattern keys *: Get all keys in the current redis database
EXISTSkey Check if the given key exists
TYPEkey Returns the type of the value stored by the key
DELkey This command is used to delete the key when the key exists

Guess you like

Origin blog.csdn.net/stange1/article/details/129473482