EXPIRETIME(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– EXPIRETIME πŸ’– (that's the page for expiretime, from the Valkey Command Manual, section 3valkey β€” bestie you're gonna love this one)

✨ NAME ✨

expiretime β€” gives you back the expiration time of a key, as a Unix timestamp. that's it. that's the whole job. πŸŽ€


🌸 SYNOPSIS 🌸

EXPIRETIME key

one key. one answer. no drama. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you've got a key, and that key has a little countdown clock on it. EXPIRETIME reads that clock and tells you the absolute Unix timestamp (that means seconds since January 1, 1970, the og epoch, the moment time itself said "hey") at which your key is gonna expire. ⏰✨

like, not "in 40 seconds", but "at 33177117420". absolute. final. iconic.

also, if you want the same tea but with millisecond resolution, go look at the valkey-pexpiretime(7) PEXPIRETIME command. same info, finer detail, still slay. πŸ‘‘


πŸ’œ REPLY πŸ’œ

you're gonna get one of these three, and they're all valkey-protocol(7) integer replies, no cap:

  • valkey-protocol(7) Integer reply β€” the expiration Unix timestamp, in seconds. the actual answer, the main character. πŸ•
  • valkey-protocol(7) Integer reply β€” -1 if the key exists but has no associated expiration time. like, she's alive but she's immortal. no clock, no expiry. 😌
  • valkey-protocol(7) Integer reply β€” -2 if the key does not exist. rip. she's not even here. πŸ’€

⚑ COMPLEXITY ⚑

O(1)

constant time. instant. faster than your ex replying to a text. πŸ”₯


πŸ” ACL CATEGORIES πŸ”

@fast @keyspace @read

fast, keyspace-y, read-only. the holy trinity of "i'm just looking, i promise." 🫢


πŸ“œ HISTORY πŸ“œ

  • Available since: 7.0.0 β€” so she's a newer girly, born in the 7.0.0 era. 🌈

🌟 EXAMPLES 🌟

here's the whole vibe, verbatim, go off:

127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> EXPIREAT mykey 33177117420
(integer) 1
127.0.0.1:6379> EXPIRETIME mykey
(integer) 33177117420

so we set mykey to "Hello", then EXPIREAT pins its death date to 33177117420, and then EXPIRETIME reads it right back at us. 33177117420. consistency ate. πŸ“


πŸ‘€ SEE ALSO πŸ‘€

the whole friend group, fr fr:

copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(3valkey), expireat(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), pttl(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)


lowkey a note: EXPIRETIME gives you the absolute timestamp, not a countdown. if you wanted "how many seconds left", that's a different girly (TTL). don't mix them up bestie, iykyk. πŸ™ˆ

okay that's the whole page!! πŸ’– this one's from Valkey version 9.0.0, dated 2025-10-21 β€” so go forth, check your expirations, and stay iconic. mwah. πŸ’…βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from