PTTL(3valkey)
β¨ PTTL β the "how much time do you have left bestie" command β¨
okay so this is pttl, straight outta the Valkey Command Manual (that's the manual name, folding it in here like a lil name tag π). it tells you how long a key has to live, in milliseconds, and honestly? it's giving stopwatch energy. β±οΈ
π NAME π
pttl β Returns the expiration time in milliseconds of a key. no cap, that's the whole job description. π«Ά
πΈ SYNOPSIS πΈ
PTTL key
that's it. one lil argument. iconic minimalism. π
π¦ DESCRIPTION π¦
okay so, like valkey-ttl(7) TTL β this command does the exact same thing, it returns the remaining time to live of a key that has an expire set. the sole difference (and this is the whole personality of PTTL fr fr) is that TTL hands you the remaining time in seconds, while PTTL hands it to you in milliseconds. more digits, more drama, more precision. β¨
and when things go sideways, the command returns these values:
- The command returns
-2if the key does not exist. π - The command returns
-1if the key exists but has no associated expire. π
bestie those negative numbers are not a TTL, they're lil error codes wearing a number costume. don't get played. π
β REPLY β
One of the following, pick your fighter:
- valkey-protocol(7) Integer reply: TTL in milliseconds. π
- valkey-protocol(7) Integer reply:
-1if the key exists but has no associated expiration. π - valkey-protocol(7) Integer reply:
-2if the key does not exist. π³οΈ
π COMPLEXITY π
constant time, baby. one lookup, zero sweat, main character energy only. π₯
π ACL CATEGORIES π
@fast @keyspace @read
π§ HISTORY π§
- Available since: 2.6.0 β an elder, a legend, a pioneer. π
- Changed in 2.8.0: Added the
-2reply. the glow-up era. β¨
π EXAMPLES π
watch it in action, bestie:
127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> EXPIRE mykey 1
(integer) 1
127.0.0.1:6379> PTTL mykey
(integer) 989
see how 989 is just under 1000? that's because the second was already tickin' away. iykyk. π¦
π SEE ALSO π
your recommended reading list, all the siblings and cousins:
copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(3valkey), expireat(3valkey), expiretime(3valkey), keys(3valkey), migrate(3valkey), move(3valkey), object(3valkey), object-encoding(3valkey), object-freq(3valkey), object-help(3valkey), object-idletime(3valkey), object-refcount(3valkey), persist(3valkey), pexpire(3valkey), pexpireat(3valkey), pexpiretime(3valkey), randomkey(3valkey), rename(3valkey), renamenx(3valkey), restore(3valkey), scan(3valkey), sort(3valkey), sort_ro(3valkey), touch(3valkey), ttl(3valkey), type(3valkey), unlink(3valkey), wait(3valkey), waitaof(3valkey)
okay that's the whole page, you ate that reading session fr fr π«Ά this was Valkey 9.0.0, dated 2025-10-21 β go check on your keys' TTLs before they ghost you, periodt. πβ¨
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms