String
This is the simplest type of redis. If you only use this type, Redis is like a memcached server that can be persisted
127.0.0.1:6379> Set MyKey Somevalueok
127.0.0.1:6379> get MyKey "somevalue"
SET Command
Set key value [ex seconds] [px milliseconds] [nx|xx]
Ex: set key expiration time, unit seconds
PX: Set the expiration time of the key, in milliseconds
NX: The key cannot be set until it exists
XX: The value of key is set only when keys exist
127.0.0.1:6379> set MyKey newval NX (nil)
127.0.0.1:6379> Set MyKey newval Xxok
127.0.0.1:6379> set MyKey 30seconds ex 30ok127.0.0.1:6379> ttl MyKey (integer) 27
The TTL command is used to view the expiry time of key keys
Using set to implement lock mechanism
Set Resource-name anystring NX ex Max-lock-time
127.0.0.1:6379> set Stock-NX ex 3000OK
Atomic Increment
127.0.0.1:6379> Set Counter 100
Ok
(integer) 101
127.0.0.1:6379> Incrby Counter 50
(integer) 151
127.0.0.1:6379> DECR counter
(integer) 150
Set or store multiple values at once
127.0.0.1:6379> Mset a ten b c 30ok127.0.0.1:6379> mget a B C1) "10" 2) "20" 3 "30"
Mget returns an array of strings
Redis data Type (string)