Redis lua graph traversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--"9e4c3550b2961d085916ecdead255cde6b450f6b" | |
local ret = KEYS[1] | |
local limit = 100 | |
while limit ~= 0 do | |
local pres = redis.pcall("GET", ret) | |
if pres == nil or type(pres) == "boolean" then return ret end | |
ret = pres | |
limit = limit - 1 | |
end | |
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import sys | |
tot = 1000 | |
split = int(sys.argv[1]) | |
if tot % split != 0 : | |
print "first param should divide 1000 perfectly" | |
sys.exit(1) | |
rows = tot/split | |
cols = split | |
rc = redis.StrictRedis(host='127.0.0.1') | |
for i in xrange(rows): | |
rc.delete(i*cols) | |
for j in xrange(1, cols): | |
rc.set(i*cols + j, i*cols + j - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import time | |
import sys | |
tc = int(sys.argv[1]) | |
rc = redis.StrictRedis(host='127.0.0.1') | |
def get_root(val): | |
return rc.evalsha("9e4c3550b2961d085916ecdead255cde6b450f6b", 1, val) | |
start = time.time() | |
print "start", start | |
for i in xrange(tc): | |
get_root(str(i%1000)) | |
end = time.time() | |
print "end ", end | |
print end-start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
import time | |
import sys | |
tc = int(sys.argv[1]) | |
rc = redis.StrictRedis(host='127.0.0.1') | |
def get_root(val): | |
limit = 100 | |
while limit > 0: | |
pres = rc.get(val) | |
if pres == None : return val | |
val = pres | |
limit -= 1 | |
return val | |
start = time.time() | |
print "start", start | |
for i in xrange(tc): | |
get_root(str(i%1000)) | |
end = time.time() | |
print "end ", end | |
print end-start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment