Last active
September 8, 2016 01:19
-
-
Save clayadavis/0eefb18ce66fe2c80ef7aff5f46240f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 redis | |
# Number of records to move at once | |
N = 10000 | |
# DB number and key | |
DB = 3 | |
KEY = 'deletion_notices' | |
source = redis.StrictRedis('<source host>', db=DB) | |
dest = redis.StrictRedis('<dest host>', db=DB) | |
source.ping() | |
dest.ping() | |
records_moved = 0 | |
records_to_move = source.llen(KEY) | |
print("Moving %i records..." % (records_to_move // 1000)) | |
while True: | |
chunk = source.lrange(KEY, 0, N-1) | |
if not chunk: | |
break | |
dest.rpush(KEY, *chunk) | |
source.ltrim(KEY, N, -1) | |
records_moved += len(chunk) | |
print('{}k records moved, {}k records to go'.format( | |
records_moved // 1000, (records_to_move - records_moved) // 1000)) | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment