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
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].

View File

@ -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__":

View File

@ -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()