🔴 Redis
Beginner
What do the SET and GET commands do in Redis?
Answer
SET key value stores a string value under the given key, overwriting any existing value. GET key retrieves the value for a key, returning nil if the key doesn't exist. SET also supports several important options in one atomic command: EX seconds sets a Time-To-Live (TTL) so the key expires automatically, NX only sets the key if it doesn't already exist (useful for distributed locks), and XX only sets it if the key already exists. Example: SET session:user123 "data" EX 3600 NX atomically creates a session key that expires in one hour only if it doesn't already exist — a single-command distributed locking primitive.