No disrespect Matthew, but you're doing it very very wrong.
Very #1: do not use `KEYS`, use `SCAN` instead. Your script is not only blocking the server, it also consumes a lot of RAM just for holding them while iterating.
Very #2: do not use JSON to encode, and no need for the conditional-read-by-type - just use Redis' `DUMP`
P.S. there may be more wrongness ;)