1.1 string
Overview
String is the most basic type of redis . You can understand it as exactly the same type as memcached. A key corresponds to a value. The string type is binary safe. This means that the redis string can contain any data. Such as jpg images or serialized objects. The string type is the most basic data type of Redis, and a key can store up to 512MB.
Basic operation
set key value [EX second]
meaning
It is to add a string type key and value to redis, if it can exist, it will be overwritten, if it can not exist, create a new one
ex refers to the expiration time of the current key, in seconds
px refers to the expiration time of the current key, in milliseconds
get key
meaning
Get the value corresponding to the key, but the data type of the key must be string
mset key value [key value ...]
meaning
It is the batch processing version of set, which can add multiple kvs at once
mget key1 [key2]
meaning
Each time you can get the value corresponding to multiple keys
getset key value
meaning
Set the value of the given key to value, and return the old value of the key (old value)
Set the expiration time of the key
-
SETEX key seconds value associate the value value to the key, and set the key expiration time to seconds (in seconds)
-
PSETEX key milliseconds value This command is similar to the SETEX command, but it sets the lifetime of the key in milliseconds instead of seconds as in the SETEX command.
SETNX key value
meaning
Only set the value of the key when the key does not exist
MSETNX key value [key value ...]
[The above learning is based on the SDUT course training materials. 】