RESTORE(3valkey)

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

✨ 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 when key already exists β€” unless you use the REPLACE modifier. 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 REPLACE modifier.
  • Changed in 5.0.0: Added the ABSTTL modifier.
  • Changed in 5.0.0: Added the IDLETIME and FREQ options.

⭐ 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 πŸ‘‘


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