From ac71ec598cd8d48add0a6278079d11bfc703f564 Mon Sep 17 00:00:00 2001 From: holys Date: Fri, 8 Aug 2014 18:37:23 +0800 Subject: [PATCH] update readme --- tools/redis_import/README.md | 15 +++++++++++++-- tools/redis_import/redis_import.py | 23 ++++++++++++++++++++--- tools/redis_import/test.py | 1 - 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/tools/redis_import/README.md b/tools/redis_import/README.md index e36b629..44ee28a 100644 --- a/tools/redis_import/README.md +++ b/tools/redis_import/README.md @@ -1,8 +1,19 @@ ## Notice -1. We don't support `set` data type. +1. The tool doesn't support `set` data type. +2. The tool doesn't support `bitmap` data type. 2. Our `zset` use integer instead of double, so the zset float score in Redis will be **converted to integer**. 3. Only Support Redis version greater than `2.8.0`, because we use `scan` command to scan data. - Also, you need `redis-py` greater than `2.9.0` + Also, you need `redis-py` greater than `2.9.0`. + + +## Usage + + + $ python redis_import.py redis_host redis_port redis_db ledis_host ledis_port [True] + +The option `True` means convert `set` to `zset` or not, if not, set it to `False`. + +We will use the same db index as redis. That's to say, data in redis[0] will be transfer to ledisdb[0]. \ No newline at end of file diff --git a/tools/redis_import/redis_import.py b/tools/redis_import/redis_import.py index 820487b..b3d0cfa 100644 --- a/tools/redis_import/redis_import.py +++ b/tools/redis_import/redis_import.py @@ -95,6 +95,8 @@ def copy_keys(redis_client, ledis_client, keys, convert=False): def scan(redis_client, count=1000): keys = [] total = redis_client.dbsize() + if total > 1000: + print "It may take a while, be patient please." first = True cursor = 0 @@ -102,14 +104,13 @@ def scan(redis_client, count=1000): cursor, data = redis_client.scan(cursor, count=count) keys.extend(data) first = False - print len(keys) - print total assert len(keys) == total return keys, total def copy(redis_client, ledis_client, count=1000, convert=False): if scan_available(redis_client): + print "\nTransfer begin ...\n" keys, total = scan(redis_client, count=count) copy_keys(redis_client, ledis_client, keys, convert=convert) @@ -138,6 +139,18 @@ def usage(): print usage % os.path.basename(sys.argv[0]) +def get_prompt(choice): + yes = set(['yes', 'ye', 'y', '']) + no = set(['no', 'n']) + + if choice in yes: + return True + elif choice in no: + return False + else: + sys.stdout.write("Please respond with 'yes' or 'no'") + + def main(): if len(sys.argv) < 6: usage() @@ -148,6 +161,10 @@ def main(): if len(sys.argv) == 7 and sys.argv[-1] == "True" or sys.argv[-1] == "true": convert = True + choice = raw_input("[y/N]").lower() + if not get_prompt(choice): + sys.exit("No proceed") + redis_c = redis.Redis(host=redis_host, port=int(redis_port), db=int(redis_db)) ledis_c = ledis.Ledis(host=ledis_host, port=int(ledis_port), db=int(redis_db)) try: @@ -163,7 +180,7 @@ def main(): sys.exit() copy(redis_c, ledis_c, convert=convert) - print "done\n" + print "Done\n" if __name__ == "__main__": diff --git a/tools/redis_import/test.py b/tools/redis_import/test.py index a7f7f09..4e77efc 100644 --- a/tools/redis_import/test.py +++ b/tools/redis_import/test.py @@ -132,7 +132,6 @@ def test_ttl(): # invalid.append(key) assert rds.ttl(key) == ledis_ttl(lds, key, k_type) - print len(invalid) if __name__ == "__main__": test()