Skip to content

Instantly share code, notes, and snippets.

@charsyam
Last active December 17, 2015 16:20
Show Gist options
  • Save charsyam/5638416 to your computer and use it in GitHub Desktop.
Save charsyam/5638416 to your computer and use it in GitHub Desktop.
generate set-tx script.
import os,sys
f = open(sys.argv[1], "w")
for i in xrange(100000):
key = "a%s"%(str(i))
data = "\"local ts = redis.call('lindex', KEYS[1], 1) or -1\\r\\nif tonumber(ARGV[2]) > tonumber(ts) then\\r\\nredis.call('del', KEYS[1])\\r\\nredis.call('rpush', KEYS[1], ARGV[1], ARGV[2])\\r\\nreturn ARGV[1]\\r\\nelse\\r\\nreturn {err='Stale'}\\r\\nend\""
cmd = "EVAL %s %s %s %s %s\n"%(data, 1, key, i, i);
f.write(cmd)
cmd = "EVAL %s %s %s %s %s\n"%(data, 1, key, i, i+100);
f.write(cmd)
cmd = "EVAL %s %s %s %s %s\n"%(data, 1, key, i, i+10);
f.write(cmd)
f.close()
import os,sys
f = open(sys.argv[1], "w")
for i in xrange(100000):
key = "a%s"%(str(i))
cmd = "set %s %s wt %s\n"%(key, i, i);
f.write(cmd)
cmd = "set %s %s wt %s\n"%(key, i, i+100);
f.write(cmd)
cmd = "set %s %s wt %s\n"%(key, i, i+10);
f.write(cmd)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment