Last active
June 1, 2018 22:02
-
-
Save nqbao/eea114a2078d849a1f31d02607ffa8a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import redis | |
from concurrent.futures import ThreadPoolExecutor | |
from tqdm import tqdm | |
source = redis.Redis.from_url(sys.argv[1]) | |
dest = redis.Redis.from_url(sys.argv[2]) | |
print "Migrating %s -> %s" % (source, dest) | |
def migrate_key(k): | |
type_ = source.type(k) | |
# print "%s:%s" % (k, type_) | |
if type_ == 'hash': | |
data = source.hgetall(k) | |
dest.hmset(k, data) | |
elif type_ == 'string': | |
dest.set(k, source.get(k)) | |
else: | |
raise NotImplementedError() | |
# dest.flushall() | |
with ThreadPoolExecutor(4) as pool: | |
keys = source.keys() | |
with tqdm(xrange(len(keys))) as bar: | |
it = pool.map(migrate_key, source.keys()) | |
for _ in it: | |
bar.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment