Home > Database > Redis > body text

How to apply Redis keys and common database instructions

王林
Release: 2023-06-02 22:43:54
forward
1149 people have browsed it

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template