update readme

This commit is contained in:
holys 2014-08-08 18:37:23 +08:00
parent e83965bfcc
commit ac71ec598c
3 changed files with 33 additions and 6 deletions

View File

@ -1,8 +1,19 @@
## Notice ## 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 2. Our `zset` use integer instead of double, so the zset float score in Redis
will be **converted to integer**. will be **converted to integer**.
3. Only Support Redis version greater than `2.8.0`, because we use `scan` command to scan data. 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].

View File

@ -95,6 +95,8 @@ def copy_keys(redis_client, ledis_client, keys, convert=False):
def scan(redis_client, count=1000): def scan(redis_client, count=1000):
keys = [] keys = []
total = redis_client.dbsize() total = redis_client.dbsize()
if total > 1000:
print "It may take a while, be patient please."
first = True first = True
cursor = 0 cursor = 0
@ -102,14 +104,13 @@ def scan(redis_client, count=1000):
cursor, data = redis_client.scan(cursor, count=count) cursor, data = redis_client.scan(cursor, count=count)
keys.extend(data) keys.extend(data)
first = False first = False
print len(keys)
print total
assert len(keys) == total assert len(keys) == total
return keys, total return keys, total
def copy(redis_client, ledis_client, count=1000, convert=False): def copy(redis_client, ledis_client, count=1000, convert=False):
if scan_available(redis_client): if scan_available(redis_client):
print "\nTransfer begin ...\n"
keys, total = scan(redis_client, count=count) keys, total = scan(redis_client, count=count)
copy_keys(redis_client, ledis_client, keys, convert=convert) copy_keys(redis_client, ledis_client, keys, convert=convert)
@ -138,6 +139,18 @@ def usage():
print usage % os.path.basename(sys.argv[0]) 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(): def main():
if len(sys.argv) < 6: if len(sys.argv) < 6:
usage() usage()
@ -148,6 +161,10 @@ def main():
if len(sys.argv) == 7 and sys.argv[-1] == "True" or sys.argv[-1] == "true": if len(sys.argv) == 7 and sys.argv[-1] == "True" or sys.argv[-1] == "true":
convert = 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)) 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)) ledis_c = ledis.Ledis(host=ledis_host, port=int(ledis_port), db=int(redis_db))
try: try:
@ -163,7 +180,7 @@ def main():
sys.exit() sys.exit()
copy(redis_c, ledis_c, convert=convert) copy(redis_c, ledis_c, convert=convert)
print "done\n" print "Done\n"
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -132,7 +132,6 @@ def test_ttl():
# invalid.append(key) # invalid.append(key)
assert rds.ttl(key) == ledis_ttl(lds, key, k_type) assert rds.ttl(key) == ledis_ttl(lds, key, k_type)
print len(invalid)
if __name__ == "__main__": if __name__ == "__main__":
test() test()