forked from mirror/ledisdb
Merge pull request #86 from holys/develop
add data migration support for data type Set
This commit is contained in:
commit
84e45be7a9
|
@ -1,6 +1,5 @@
|
|||
## Notice
|
||||
|
||||
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**.
|
||||
|
|
|
@ -35,7 +35,7 @@ def set_ttl(redis_client, ledis_client, key, k_type):
|
|||
"string": ledis_client.expire,
|
||||
"list": ledis_client.lexpire,
|
||||
"hash": ledis_client.hexpire,
|
||||
"set": ledis_client.zexpire,
|
||||
"set": ledis_client.sexpire,
|
||||
"zset": ledis_client.zexpire
|
||||
}
|
||||
timeout = redis_client.ttl(key)
|
||||
|
@ -46,6 +46,7 @@ def set_ttl(redis_client, ledis_client, key, k_type):
|
|||
def copy_key(redis_client, ledis_client, key, convert=False):
|
||||
global entries
|
||||
k_type = redis_client.type(key)
|
||||
|
||||
if k_type == "string":
|
||||
value = redis_client.get(key)
|
||||
ledis_client.set(key, value)
|
||||
|
@ -66,6 +67,7 @@ def copy_key(redis_client, ledis_client, key, convert=False):
|
|||
entries += 1
|
||||
|
||||
elif k_type == "zset":
|
||||
# dangerous to do this?
|
||||
out = redis_client.zrange(key, 0, -1, withscores=True)
|
||||
pieces = od()
|
||||
for i in od(out).iteritems():
|
||||
|
@ -74,6 +76,14 @@ 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":
|
||||
mbs = list(redis_client.smembers(key))
|
||||
|
||||
if mbs is not None:
|
||||
ledis_client.sadd(key, *mbs)
|
||||
set_ttl(redis_client, ledis_client, key, k_type)
|
||||
entries += 1
|
||||
|
||||
else:
|
||||
print "KEY %s of TYPE %s is not supported by LedisDB." % (key, k_type)
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ 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."
|
||||
|
@ -64,10 +67,9 @@ 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")
|
||||
copy(rds, lds, convert=True)
|
||||
|
||||
# for all keys
|
||||
|
@ -101,6 +103,7 @@ def ledis_ttl(ledis_client, key, k_type):
|
|||
"list": lds.lttl,
|
||||
"hash": lds.httl,
|
||||
"zset": lds.zttl,
|
||||
"set": lds.sttl,
|
||||
}
|
||||
return ttls[k_type](key)
|
||||
|
||||
|
@ -115,6 +118,9 @@ def test_ttl():
|
|||
assert ledis_ttl(lds, key, k_type) > 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
rds.flushdb()
|
||||
lds.flushdb()
|
||||
|
||||
test()
|
||||
test_ttl()
|
||||
print "Test passed."
|
||||
|
|
Loading…
Reference in New Issue