I was able to get this to work, my original attempt above was actually conceptually right on. There was a small logic error that caused my sanity check to fail.
I experimented with base64 per Tw Bert's suggestion. It is not necessary, but I might use it. I can throw the results straight from redis.get
into my mysql insert statement and pull it out for my sanity check and it works fine. I can also base64 encode what I put in mysql, and then base64 decode it when I read it out of mysql. Preliminarily, using base64 encoding appears to cost me an additional ~20% of disk within mysql compared with the raw binary. I don't think I care about this, however, and might be willing to pay that cost for the comfort of having the data in something ascii so I can "see" it better.
I can now couple this with some basic key selection and backup to disk any subset of keys I want to archive off of redis. I hope this helps somebody in the future.
UPDATE: It turns out that I didn't do this. My solution was pretty simple and didn't warrant the complexity described above. The naming structure of my keys was such that the sharding value was at the beginning followed by the details of that key. So, I did four things:
(1) I ran KEYS id_123*
to get all the keys I wanted to archive (there are few keys, so KEYS
isn't a huge blocker, use SCAN
if you have a ton of keys)
(2) Spin up a new redis-server (it could be on the same machine, with a different port)
(3) MIGRATE
all of the found keys to the new redis-server.
(4) Issue a SAVE
to get an RDB file and do with that what you please.
This is pretty simple, and allows you to keep it in "redis" format, so re-ingesting it later is pretty simple.