Skip to content

Instantly share code, notes, and snippets.

@williamsjj
Created June 22, 2010 22:47
Show Gist options
  • Select an option

  • Save williamsjj/449223 to your computer and use it in GitHub Desktop.

Select an option

Save williamsjj/449223 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from twisted.internet import defer, reactor, threads
import redis
import uuid
import time
def do_redis_in_thread(uuid_str, thread_num):
print "[%s] Thread %d Pre-Connect" % (str(time.clock()), thread_num)
r = redis.Redis(host="localhost", port=6379, db=15)
val = r.setnx(uuid_str, "")
print "[%s] Thread %d SETNX Result: %s" % (str(time.clock()), thread_num, val)
r.expire(uuid_str, 300)
r.connection.disconnect()
def errFailure(failure):
failure.printTraceback
if __name__ == "__main__":
master_uuid = str(uuid.uuid1())
for i in range(30):
threads.deferToThread(do_redis_in_thread, master_uuid, i).addErrback(errFailure)
reactor.suggestThreadPoolSize(300)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment