SET / GET

SET stores a string value for a key. GET retrieves the value. SET can optionally set expiry (EX seconds, PX milliseconds) and conditional flags (NX = only if not exists, XX = only if exists).

Syntax

redis
SET key value [EX seconds] [NX|XX]
GET key

Example

redis
SET user:1:name "Alice"
GET user:1:name
# "Alice"

SET session:abc "user:1" EX 3600
SET counter 0 NX