Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dump and restore data of a specific key in redis

I want to take backup of a particular key in my redis which have multiple keys. My redis has many keys and I don't want to take full backup of my redis data. I have been going through http://redis.io/commands. There I found that there is a command dump by which I can take the dump of a specific key as follows:

 redis> dump "myKey"

But is giving output in hexadecimal format in redis console only. Is it possible to store the data for a specific key in a file and later import it to that key?

like image 207
Joy Avatar asked Feb 18 '14 07:02

Joy


1 Answers

In case you are trying to dump/restore a key from the command line (which is what I needed to do when I found this question), Redis has some non-obvious quirks. Please see this answer for a more detailed explanation.

The short answer is to dump/restore as follows:

bwood@mybox:~$ redis-cli --raw dump mykey | head -c-1 > myfile
bwood@mybox:~$ cat myfile | redis-cli -x restore mynewkey 0
like image 79
Brendan Wood Avatar answered Sep 20 '22 21:09

Brendan Wood