Skip to content

Instantly share code, notes, and snippets.

@dotslash
Last active April 19, 2017 20:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotslash/5238a225072d2e74627c to your computer and use it in GitHub Desktop.
Save dotslash/5238a225072d2e74627c to your computer and use it in GitHub Desktop.
Redis lua graph traversal
--"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
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)
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
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