04 data type 1:string
# introduction to string
String type is the most basic data type of redis. A key corresponds to a value, and a key can store a maximum 512Mb.
String is binary secure.
# Common commands:
> set mykey "dang"
OK
> get mykey
"dang"
> set mykey "nihao" # multiple assignments will overwrite the original value
OK
> get mykey
"nihao"
> mset key1 1 key2 2 key3 e # multiple assignments
OK
> mget key1 key2 key3 # take multiple values
1) "1"
2) "2"
3) "e"
> setnx mykey 111I returned 0
(integer) 0
> setnx mykey2 111 # returns 1
(integer) 1
> get mykey2
"111"
# setnx if key exists, 0 is returned, and the existing value is not overwritten. The key is created directly if it does not exist.
> setex key6 30 yes # sets the expiration time, with the validity period in front and the value in the end
OK
> ttl key6 # gets the expiration time. If there is no expiration time,-1 is returned.
(integer) 25
> ttl mykey2
(integer)-1