The Redis DUMP
command serialises the value stored at a specified key in a Redis-specific format and returns it to the user.
The serialisation format contains a 64-bit checksum that is used to make sure errors will be detected. The values are in the same format used by the RDB. Also, an RDB version is encoded inside the serialised value, so that different Redis versions with incompatible RDB formats will refuse to process the serialised value.
Syntax
DUMP key
Where key
is the key for whose value we want to serialise.
Example
Suppose we set a key/value pair:
SET type "Dog"
Result:
OK
In this case, type
the key and "Dog"
is its value.
Now let’s use DUMP
against that value:
DUMP type
Result:
"\x00\x03Dog\n\x00\x14\x069\xb24\x14\xe4\xd6"
Note that the serialised value does not contain expire information. We can use the TTL
or PTTL
commands to get expire information for a given key.
When the Key Doesn’t Exist
If the key doesn’t exist, DUMP
returns nil
:
DUMP nonexistentkey
Result:
(nil)
Restore the Value
We can use the RESTORE
command to restore the serialised data back to its original form.