Command prototypes |
Complexity of Time |
return value |
Command description |
APPEND Key value |
O (1) |
The length of the value after append |
If the key already exists, the append command appends the data for the parameter value to the end of the existing value. If the key does not exist, the append command will create a new key/value. |
DECR key |
O (1) |
The value after descending |
Decrements the value of the specified key by 1. If the key does not exist, its initial value is 0, and after decr its value is-1. If the value of value cannot be converted to an integer value, such as Hello, the operation fails and returns the appropriate error message. Note: The value range for this operation is a 64-bit signed integer. |
INCR Key |
O (1) |
The value after increment |
Increments the value of the specified key by 1. If the key does not exist, its initial value is 0, and after incr its value is 1. If the value of value cannot be converted to an integer value, such as Hello, the operation fails and returns the appropriate error message. Note: The value range for this operation is a 64-bit signed integer. |
Decrby Key Decrement |
O (1) |
The value after reduction |
The value of the specified key is reduced by decrement. If the key does not exist, its initial value is 0, and after decrby its value is-decrement. If the value of value cannot be converted to an integer value, such as Hello, the operation fails and returns the appropriate error message. Note: The value range for this operation is a 64-bit signed integer. |
Incrby Key Increment |
O (1) |
The value after the increment. |
Adds the value atomicity of the specified key to increment. If the key does not exist, its initial value is 0, and after incrby its value is increment. If the value of value cannot be converted to an integer value, such as Hello, the operation fails and returns the appropriate error message. Note: The value range for this operation is 64 bits to get the value of the specified key. If the Value associated with the key is not of type string, Redis returns an error message because the GET command can only be used to get string Value. Signed integral type. |
GET Key |
O (1) |
The value associated with the key, if the key does not exist, returns nil. |
|
SET Key value |
O (1) |
Always return "OK". |
Sets the key to hold the specified string value, overwriting its original value if the key already exists. |
Getset Key value |
O (1) |
Returns the original value of the key, or nil if the key does not exist before. |
The atomic setting of the key is the specified value, and the original values of the key are returned. As with the Get command, the command can handle only string Value, or Redis will give you a related error message. |
STRLEN Key |
O (1) |
Returns the value character length of the specified key, or 0 if the key does not exist. |
Returns the length of the character value for the specified key, and if value is not of type string, Redis will fail and give the associated error message. |
Setex Key seconds value |
O (1) |
|
Atomicity completes two operations, one is to set the value of the key to the specified string, and set the key in the Redis server survival time (in seconds). This command is primarily used when Redis is used as a cache server. |
Setnx Key value |
O (1) |
1 indicates that the setting was successful, otherwise 0. |
If the specified key does not exist, the key is set to hold the specified string value, at which point the effect is equivalent to the SET command. Conversely, if the key already exists, the command will not take any action and return. |
SETRANGE Key Offset value |
O (1) |
The modified string value length. |
Replaces the partial string value of the specified key. Starting with offset, the length of the replacement is the string length of the third parameter of the command value, where if the value of offset is greater than the string length of the original value of the key, Redis will be padded with value (Offset-strlen (value)) The number of 0x00, and then append the new value. If the key does not exist, the command assumes the length of its original value as 0, and then appends a new value after fill offset 0x00. Since the maximum length of string value is 512M, the maximum value for offset is 536870911. Finally, it is important to note that if the command is executed with an increase in the length of the original value of the specified key, it will cause Redis to reallocate enough memory to accommodate all of the replaced strings, resulting in some performance impairment. |
GETRANGE Key Start end |
O (1) |
Sub-string |
If the truncated string is short, we can consider the time complexity of the command as O (1), or O (n), where n represents the length of the truncated substring. When the substring is truncated, the command will contain both start (0 for first character) and end character in a closed interval, and if the end value exceeds the character length of value, the command will simply intercept all character data after start. |
Setbit Key Offset value |
O (1) |
The bit original value on the specified offset. |
Sets the value of bit on the specified offset, which can only be 1 or 0, after which the command returns the original bit value on that offset. If the specified key does not exist, the command creates a new value and sets the bit value in the parameter on the specified offset. If offset is greater than the character length of value, Redis will lengthen the value and set the bit value in the parameter on the specified offset, and the bit value added in the middle is 0. Finally, it should be stated that the value of offset must be greater than 0. |
Getbit Key Offset |
O (1) |
The bit value on the specified offset. |
Returns the value of bit on the specified offset, 0 or 1. If offset exceeds the length of string value, the command returns 0, so always returns 0 for an empty string. |
MGET key [Key ...] |
O (N) |
Returns a list of values for the specified keys. |
n indicates the number of keys to get. Returns all values of the specified keys, if one of them does not exist, or if the value is not of type string, the key's value returns nil. |
MSET key value [key value ...] |
O (N) |
The command does not fail and always returns OK. |
n indicates the number of keys specified. The command atomically completes the set operation of all key/value in the parameter, and its specific behavior can be seen as executing the SET command multiple iterations. |
Msetnx key value [key value ...] |
O (N) |
1 means all keys are set successfully, and 0 means no key is modified. |
n indicates the number of keys specified. The command atomically completes the set operation of all key/value in the parameter, and its specific behavior can be seen as multiple iterations of the execution of the SETNX command. However, it is necessary to make it clear that if any of the keys in this batch are already present, the operation will all be rolled back, that is, all modifications will not take effect. |