SETEX is atomic where SET plus EXPIRE is not

Writing a cache entry and then setting its TTL is two commands, and the process can die between them. The result is a key with no expiry that will sit in memory until something evicts it — which for a cache without maxmemory-policy set is never.

# two commands: a crash between them leaks the key
SET session:91 "..."
EXPIRE session:91 3600

# one atomic command
SETEX session:91 3600 "..."

# or, on SET itself
SET session:91 "..." EX 3600 NX

The SET form with EX is the more useful of the two because it composes with NX — set only if absent, with an expiry, atomically — which is the basis of a simple distributed lock. Leaked keys are hard to notice because nothing breaks; memory just climbs until eviction starts discarding entries that were still wanted.