Syntax
SET key value [EX seconds] [PX
milliseconds] [NX|XX]
Sets the value to the key.
There are multiple options available for SET command.
Without options
127.0.0.1:6379> set a 10 OK 127.0.0.1:6379> get a "10"
EX
seconds
Sets the expire time of this
key in seconds.
127.0.0.1:6379> set a 10 ex 5 OK 127.0.0.1:6379> get a (nil)
When i call get command after
5 seconds, it returns nil.
PX
milliseconds
Sets the specified expiry time
in milliseconds.
127.0.0.1:6379> set a 10 px 5000 OK 127.0.0.1:6379> get a (nil)
When i call get command after
5 seconds, it returns nil.
NX
Sets only if key not exist.
127.0.0.1:6379> set a 10 nx OK 127.0.0.1:6379> get a "10" 127.0.0.1:6379> set b 10 OK 127.0.0.1:6379> set b 20 nx (nil) 127.0.0.1:6379> get b "10"
XX
Sets
only, if key already exists.
127.0.0.1:6379> set c 10 xx (nil) 127.0.0.1:6379> set d 10 OK 127.0.0.1:6379> set d 20 xx OK
No comments:
Post a Comment