Home  >  Article  >  Database  >  How to apply Redis keys and common database instructions

How to apply Redis keys and common database instructions

王林
王林forward
2023-06-02 22:43:541152browse

1. Redis key (key) general instructions

key features: key is a string, and the data saved in redis is obtained through key.

1. Basic key operations

##del keyThis command is used to delete the key when the key existsexists keyCheck whether the given key existstype keyReturns the type of value stored in key
Command Function
Demo results:

How to apply Redis keys and common database instructions

2. Timeliness control

CommandFunctionEXPIRE key seconds Set the expiration time for the given key in secondsPEXPIRE key millisecondsSet the expiration time of the key in millisecondsEXPIREAT key timestampEXPIREAT has a similar function to EXPIRE, and is used to set the expiration time for the key. The difference is that the time parameter accepted by the EXPIREAT command is UNIX timestamp (unix timestamp)PEXPIREAT key milliseconds-timestamp Set the timestamp of the key expiration time (unix timestamp) In millisecondsTTL keyIn seconds, returns the remaining survival time of the given key##PTTL key PERSIST key Demonstration results:
Return the remaining expiration time of the key in milliseconds
Remove the expiration time of the key, the key will be persisted

How to apply Redis keys and common database instructions3. Query mode

Commandkeys patternQuery pattern rules:
Function
Query key

How to apply Redis keys and common database instructions Demonstration results:

How to apply Redis keys and common database instructions4. Other operations

Commandrename key newkeyrenamenx key newkeyDemo results:
Function
Rename the key
Only when newkey does not exist, rename the key to newkey

How to apply Redis keys and common database instructionstwo , Database general instructions

    redis provides 16 databases for each service, numbered from 0 to 15
  • between each database Data are independent of each other
  • 1. Basic operations

Commandselect indexquitpingDemo results:
Function
Switch database
Exit
Test connection

##2. Related operationsHow to apply Redis keys and common database instructions

CommandFunctionmove key dbData movement dbsizeHow many keys are there in each databaseflushdbClear the current databaseflushallClear all databasesDemo results:

The above is the detailed content of How to apply Redis keys and common database instructions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete