PEXPIRE(3valkey)
β¨ PEXPIRE β¨
okay so bestie, quick vibe check: this is pexpire, a page straight out of the Valkey Command Manual (yes, the 3valkey girlies know π
). She sets the expiration time of a key β but in milliseconds, not seconds. tiny units, big power. periodt.
πΈ NAME πΈ
pexpire β sets the expiration time of a key in milliseconds. β±οΈβ¨
π SYNOPSIS π
PEXPIRE key milliseconds [NX | XX | GT | LT]
look at her. so simple. so iconic. π«Ά
π DESCRIPTION π
no cap, this command works exactly like valkey-expire(7) EXPIRE β same energy, same everything β except the time to live of the key is given in milliseconds instead of seconds. that's literally the whole plot twist. the way that one unit change carries the entire commandβ¦ obsessed. π
β¨ OPTIONS β¨
the PEXPIRE command supports a set of options, and yes she has range:
NXβ set expiry only when the key has no expiry. like, only if nobody's claimed the TTL yet.XXβ set expiry only when the key has an existing expiry. she only updates if there's already a timer running.GTβ set expiry only when the new expiry is greater than the current one. bigger only, bestie πLTβ set expiry only when the new expiry is less than the current one. smaller only π
important tea π΅: a non-volatile key is treated as an infinite TTL for the purpose ofGTandLT. and heads up βGT,LTandNXare mutually exclusive. pick one, you can't have all three. she's not polyamorous about this.
π REPLY π
one of the following, and it's giving valkey-protocol(7) energy:
valkey-protocol(7)Integer reply:0if the timeout was not set. for example, if the key doesn't exist, or the operation got skipped because of the arguments you provided. πvalkey-protocol(7)Integer reply:1if the timeout was set. slay. π
π₯ COMPLEXITY π₯
constant time, no dragging, she's fast fr fr. β‘
π ACL CATEGORIES π
@fast @keyspace @write
π¦ HISTORY π¦
- available since: 2.6.0
- changed in 7.0.0: added options:
NX,XX,GTandLT.
she's been around a minute, but she keeps reinventing herself. main character energy only. β¨
π EXAMPLES π
127.0.0.1:6379> SET mykey "Hello"
OK
127.0.0.1:6379> PEXPIRE mykey 1500
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) 1
127.0.0.1:6379> PTTL mykey
(integer) 1480
127.0.0.1:6379> PEXPIRE mykey 1000 XX
(integer) 1
127.0.0.1:6379> TTL mykey
(integer) 1
127.0.0.1:6379> PEXPIRE mykey 1000 NX
(integer) 0
127.0.0.1:6379> TTL mykey
(integer) 1
see how NX came back with (integer) 0? because the key already had an expiry and she said "not today." π«β¨
π SEE ALSO π
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), 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)
the whole friend group. go say hi. π«Ά
and that's the page, bestie!! π this version is from valkey 9.0.0, dated 2025-10-21 β so go forth, set those millisecond expiries, and remember: TTLs are temporary but the knowledge is forever. mwah πβ¨π¦
π¦ 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