You can set an expiration time for a key using the EX option with the SET command. For example: SET key_name "value" EX 3600 sets the key to expire in 3600 seconds (1 hour).