Redis's official website Http://redis.io is an important resource for Redis, and all the commands are listed here http://redis.io/commands.
1. Database Selection command:
SELECT index //select which database to use for the current connection
Default configuration The next Redis-server service opens 16 databases with the index bit 0~15, which can be selected using the Select command, and the REDIS-CLI connection uses the library No. 0 by default.
Note: Redis commands work on the selected library. For example, if you use "SELECT 1" to select Library 1th, then the Redis commands are used on the library, eg. the command "Keys" will only list all keys in library 1th.
2. common commands related to key:
KEYSPattern//Lists all "keys" that match the pattern and supports glob-Style Patterntype Key//detecting the type of keyEXISTSKey [Key ...] //returns the number of keys that exist in the key list/* Move and delete */MOVE Key DB//moves the key in the current database to the DB specified database del key [key...] //remove a key from the list/* Rename related */RENAMEKey Newkey//Rename Renamenx key Newkey//Renamed and executed only if the Newkey does not exist/* Survival Time related */EXPIRE key seconds//set the survival time of key, specify how much "seconds" expires after Pexpire key milliseconds//set the survival time of key, specify how much "MS" expires after expireat key timestamp//set the survival time of key, specify Pexpireat key milliseconds using "seconds" absolute time-timestamp//set key survival time, use "millisecond" absolute time to specify TTL key//returns the remaining surviving time of key, in seconds Pttl keyReturns the remaining stock time of key, in milliseconds
3. command usage and parsing
①,KEYS pattern
function: finds all keys in the current library that match the pattern pattern
complexity of Time: O (n), n is the number of keys in the current library. Use this command with caution if there are very many keys stored in the current library.
pattern: support Glob-style mode:? match 1 characters, * Match 0 or more characters, [AE] matches character "a" or "E", [^e] matches any one character outside "Non e", [a-c] matches "a/b/c" Any one of the characters that match the special character needs to be escaped with a backslash "\".
Example:
②,TYPE key
function : Returns the type of key (Redis has 5 Big data types).
Example:
③,EXISTS key [key ...]
function : Returns the number of keys that exist in the key list. If there is only one key in the list, check to see if the key exists.
time complexity : O (1)
Example:
④,MOVE Key db
function : Moves the key in the current database to the database indicated in DB, which represents the database number
time complexity : O (1)
Example:
⑤,DEL key [key ...]
function : Remove key from list
time complexity : O (n), where N is the number of "key-value pairs" that are actually landed in the list. The time complexity of deleting a string type key is O (1), and the time complexity of deleting a key with M key pairs (collection type set,hash,list,sorted set) is O (M).
Example:
⑥,RENAME key Newkey
function : Rename key to Newkey, note: If Newkey exists, this action overrides the value of Newkey.
time complexity : O (1)
Example:
⑦,rebanenx key Newkey
function : With rename, the difference is that this command executes only if the Newkey does not exist.
⑧,TTL key/ Pttl key
function : is to detect how long the key can also survive, the difference is that the TTL return value is the unit "seconds", Pttl the return value of the unit is "milliseconds." Its return value has three states:-No, a permanent survival, a value greater than 0 indicates the remaining survival time.
time complexity : O (1).
Example:
⑨,EXPIRE key seconds/ pexpire milliseconds
function : Specifies the survival time of the key. The difference is that the former unit is "seconds", the latter unit is "milliseconds".
time complexity : O (1)
Note: If you do not use Expire/pexpire/expireat/pexpireat to specify the lifecycle of a key, the default is never expire.
2. Keys related commands