forked from mirror/ledisdb
remove support for transfering redis set to ledisdb zset
This commit is contained in:
parent
057a19bb8f
commit
55e7433541
|
@ -12,8 +12,7 @@
|
|||
## Usage
|
||||
|
||||
|
||||
$ python redis_import.py redis_host redis_port redis_db ledis_host ledis_port [True]
|
||||
$ python redis_import.py redis_host redis_port redis_db ledis_host ledis_port
|
||||
|
||||
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].
|
||||
We will use the same db index as redis. That's to say, data in redis[0] will be transfer to ledisdb[0]. But if redis db `index >= 16`, we will refuse to transfer, because ledisdb only support db `index < 16`.
|
|
@ -74,15 +74,6 @@ def copy_key(redis_client, ledis_client, key, convert=False):
|
|||
set_ttl(redis_client, ledis_client, key, k_type)
|
||||
entries += 1
|
||||
|
||||
elif k_type == "set":
|
||||
if convert:
|
||||
print "Convert set %s to zset\n" % key
|
||||
members = redis_client.smembers(key)
|
||||
set_to_zset(ledis_client, key, members)
|
||||
entries += 1
|
||||
else:
|
||||
print "KEY %s of TYPE %s will not be converted to Zset" % (key, k_type)
|
||||
|
||||
else:
|
||||
print "KEY %s of TYPE %s is not supported by LedisDB." % (key, k_type)
|
||||
|
||||
|
@ -124,17 +115,10 @@ def copy(redis_client, ledis_client, count=1000, convert=False):
|
|||
print "%d keys, %d entries copied" % (total, entries)
|
||||
|
||||
|
||||
def set_to_zset(ledis_client, key, members):
|
||||
d = {}
|
||||
for m in members:
|
||||
d[m] = int(0)
|
||||
ledis_client.zadd(key, **d)
|
||||
|
||||
|
||||
def usage():
|
||||
usage = """
|
||||
Usage:
|
||||
python %s redis_host redis_port redis_db ledis_host ledis_port [True]
|
||||
python %s redis_host redis_port redis_db ledis_host ledis_port
|
||||
"""
|
||||
print usage % os.path.basename(sys.argv[0])
|
||||
|
||||
|
@ -158,8 +142,9 @@ def main():
|
|||
convert = False
|
||||
if len(sys.argv) >= 6:
|
||||
(redis_host, redis_port, redis_db, ledis_host, ledis_port) = sys.argv[1:6]
|
||||
if len(sys.argv) == 7 and sys.argv[-1] == "True" or sys.argv[-1] == "true":
|
||||
convert = True
|
||||
if int(redis_db) >= 16:
|
||||
print redis_db
|
||||
sys.exit("LedisDB only support 16 databases([0-15]")
|
||||
|
||||
choice = raw_input("[y/N]").lower()
|
||||
if not get_prompt(choice):
|
||||
|
|
|
@ -47,10 +47,6 @@ def random_zset(client, words, length=1000):
|
|||
client.zadd("zsetName", **d)
|
||||
|
||||
|
||||
def random_set(client, words, length=1000):
|
||||
client.sadd("setName", *words)
|
||||
|
||||
|
||||
def test():
|
||||
words = get_words()
|
||||
print "Flush all redis data before insert new."
|
||||
|
@ -68,13 +64,10 @@ def test():
|
|||
random_zset(rds, words)
|
||||
print "random_zset done"
|
||||
|
||||
random_set(rds, words)
|
||||
print "random_set done"
|
||||
|
||||
lds.lclear("listName")
|
||||
lds.hclear("hashName")
|
||||
lds.zclear("zsetName")
|
||||
lds.zclear("setName")
|
||||
copy(rds, lds, convert=True)
|
||||
|
||||
# for all keys
|
||||
|
@ -101,11 +94,6 @@ def test():
|
|||
z2 = lds.zrange("zsetName", 0, -1, withscores=True)
|
||||
assert z1 == z2
|
||||
|
||||
# fo set
|
||||
assert set(rds.smembers("setName")) == set(lds.zrange("setName", 0, -1))
|
||||
for key in lds.zrange("setName", 0, -1):
|
||||
assert int(lds.zscore("setName", key)) == 0
|
||||
|
||||
|
||||
def ledis_ttl(ledis_client, key, k_type):
|
||||
ttls = {
|
||||
|
@ -113,7 +101,6 @@ def ledis_ttl(ledis_client, key, k_type):
|
|||
"list": lds.lttl,
|
||||
"hash": lds.httl,
|
||||
"zset": lds.zttl,
|
||||
"set": lds.zttl
|
||||
}
|
||||
return ttls[k_type](key)
|
||||
|
||||
|
|
Loading…
Reference in New Issue