Created
August 5, 2012 13:47
-
-
Save HeartSaVioR/3264923 to your computer and use it in GitHub Desktop.
Redis bulk insert test - set
This file contains hidden or 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
# -*- encoding: utf-8 -*- | |
import sys | |
#print sys.argv | |
if len(sys.argv) < 3: | |
print "usage: %s [start] [end]" % sys.argv[0] | |
sys.exit(1) | |
start = int(sys.argv[1]) | |
end = int(sys.argv[2]) | |
import redis | |
redis = redis.Redis(host='localhost', port=6379, db=0) | |
if len(sys.argv) >= 4 and sys.argv[3] == "flushall": | |
redis.flushall() | |
import time | |
s_time = time.time() | |
with redis.pipeline() as pipe: | |
pipe.multi() | |
for i in xrange(start, end): | |
id = "%040x" % i | |
key = "abc:defghi" | |
ret = pipe.sadd(key, id) | |
if (i+1) % 1000 == 0: | |
print "Now cnt: %d" % (i+1) | |
pipe.execute() | |
pipe.multi() | |
print "Execute..." | |
pipe.execute() | |
e_time = time.time() | |
print "Done..." | |
print "Elapsed time: %0.2f" % (e_time - s_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
life saver! Thanks for this 👍