RESTORE(3valkey)
β¨ NAME β¨
restore β bestie, this one builds a key back up from its serialized glow-up. It's the reverse of DUMP, and it ate. π
πΈ SYNOPSIS πΈ
RESTORE key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds]
[FREQ frequency]
π DESCRIPTION π
Okay so picture this: you've got a blob of serialized value (the kind you got from valkey-dump(7)'s DUMP), and you want it to become a real, living, breathing key again. That's literally RESTORE's whole thing. It creates a key associated with a value that is obtained by deserializing the serialized value you hand it. Main character energy fr. π¦
If ttl is 0, the key is created with no expire at all β it just lives forever, iconic. Otherwise the expire time you specified (in milliseconds, bestie) gets set on it. β°
And if you used the ABSTTL modifier? Then ttl isn't a countdown anymore, it should represent an absolute Unix timestamp (in milliseconds) at which the key will expire. So like, a specific point in time, not a "how long from now." Different vibe entirely. π°οΈ
For eviction purposes (so the server knows who to yeet first when memory gets tight), you may use the IDLETIME or FREQ modifiers. Want the deets? Go read valkey-object(7)'s OBJECT. π
Heads up bestie: RESTORE will return aβTarget key name is busyβerror whenkeyalready exists β unless you use theREPLACEmodifier. No stealing spots in the keyspace without permission, periodt. π
Also, RESTORE checks the RDB version and the data checksum. If they don't match? Error. It's giving strict. No notes. π
π REPLY π
valkey-protocol(7) Simple string reply: OK.
π₯ COMPLEXITY π₯
O(1) to create the new key, plus an additional O(NM) to reconstruct the serialized value β where N is the number of objects composing the value and M is their average size. For small string values the time complexity is thus O(1)+O(1M) where M is small, so simply O(1). Easy. β¨
But for sorted set values the complexity is O(NMlog(N)), because inserting values into sorted sets is O(log(N)). Sorted sets really said "I'll be a little extra about it." π
π«Ά ACL CATEGORIES π«Ά
@dangerous @keyspace @slow @write
π HISTORY π
- Available since: 2.6.0 π
- Changed in 3.0.0: Added the
REPLACEmodifier. - Changed in 5.0.0: Added the
ABSTTLmodifier. - Changed in 5.0.0: Added the
IDLETIMEandFREQoptions.
β EXAMPLES β
127.0.0.1:6379> DEL mykey
(integer) 0
127.0.0.1:6379> RESTORE mykey 0 "\n\x17\x17\x00\x00\x00\x12\x00\x00\x00\x03\x00\
x00\xc0\x01\x00\x04\xc0\x02\x00\x04\xc0\x03\x00\
xff\x04\x00u#<\xc0;.\xe9\xdd"
OK
127.0.0.1:6379> TYPE mykey
list
127.0.0.1:6379> LRANGE mykey 0 -1
1) "1"
2) "2"
3) "3"
Look at that. Deleted it, restored it from a cursed little string of escapes, and boom β it's a list with 1, 2, 3 inside. We love a resurrection arc. π§
π 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)pexpire(3valkey)pexpireat(3valkey)pexpiretime(3valkey)pttl(3valkey)randomkey(3valkey)rename(3valkey)renamenx(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, bestie, go restore something iconic. π This was the Valkey Command Manual entry for RESTORE, version 9.0.0, dated 2025-10-21 β and yes I remembered the date, because I always remember. Slay, 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