table of Contents
Redis general instructions
key basic operation
Key expansion operation (timeliness control)
Key extended operation (query mode)
key other operations
Database general instructions
db basic operation
db related operations
Redis general instructions
key feature
- The key is a string, and the data saved in redis is obtained through the key
What operations should the key design?
- Operations related to the state of the key itself, such as deleting, determining existence, obtaining type, etc.
- For key validity control related operations, such as: valid period setting, judging whether it is valid, switching of valid status, etc.
- For quick key query operation, for example: query key according to specified strategy
- ……
key basic operation
Delete the specified key
|
of the key
|
Get whether the key exists
|
exists key
|
Get the type of key
|
type key
|
Key expansion operation (timeliness control)
Set the validity period for the specified key
|
expire key seconds pexpire key milliseconds expireat key timestamp pexpireat key milliseconds-timestamp |
Get the effective time of the key
|
ttl key
pttl key
|
Switch the key from time-sensitive to permanent
|
persist
key
|
Key extended operation (query mode)
keys pattern
* |
Match any number of any symbols |
? |
With an arbitrary symbol |
[ ] |
Matches a specified symbol |
keys * |
Query all |
keys it* |
Query all beginning with it |
keys * at home |
Query all ending with heima |
keys at home |
Query all the first two characters are arbitrary, and the back ends with heima |
keys user:? |
Query all starting with user: and any last character |
keys u[st]er:1 |
Query all starting with u, ending with er:1, containing a letter, s or t |
key other operations
Rename the key
|
rename key newkey renamenx key newkey |
Sort all keys
|
sort
|
Other key common operations
|
help @generic
|
Database general instructions
Key duplication problem
- key is defined by the programmer
- During the use of redis, with the increase in the amount of operating data, a large amount of data and corresponding keys will appear
- The data does not distinguish between types, and the categories are mixed together, and it is easy to repeat or conflict
solution
- redis provides 16 databases for each service , numbered from 0 to 15
- Data between each database is independent of each other
db basic operation
Switch database
|
select
index
|
Other operations
|
quit ping echo message |
db related operations
Data movement
|
move
key db
|
Data clear
|
dbsize flushdb flushall |