Skip to content

Instantly share code, notes, and snippets.

@nqbao
Last active June 1, 2018 22:02
Show Gist options
  • Save nqbao/eea114a2078d849a1f31d02607ffa8a3 to your computer and use it in GitHub Desktop.
Save nqbao/eea114a2078d849a1f31d02607ffa8a3 to your computer and use it in GitHub Desktop.
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