Redis Cheat Sheet/Set value with TTL

Store a string and set expiry atomically.

Section: Strings

Set value with TTL

bash
bash
SET session:token 'abc123' EX 3600

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Strings
Set a string value
Write a string value.
OpenIn sheetbashsame section
Set only if key does not exist
Common lock-style pattern using NX and EX.
OpenIn sheetbashsame section
Get a string value
Read a string value.
OpenIn sheetbashsame section
Get and delete a key
Atomically fetch and delete a key.
OpenIn sheetbashsame section
Get a value and update expiration
Read and extend or modify TTL atomically.
OpenIn sheetbashsame section
Get multiple values
Fetch many strings in one round trip.
OpenIn sheetbashsame section