def send_loop(): c = RedisClient() sleep(1) print 'SEND S', time.time() for x in xrange(500): c.publish("foo", "bar") print 'SEND E', time.time()
def take_lock(): global counter client = RedisClient('localhost', 6379) try: with RedisLock(client, key, timeout=lock_timeout) as lock: v = client.get(incr_key) sleep(random.random() * sleep_factor) client.set(incr_key, int(v) + 1) counter += 1 except LockNotAcquired: pass
def main(): client = RedisClient('localhost', 6379) client.delete(key) client.set(incr_key, 0) for _ in xrange(500): fork(take_lock) if random.random() > 0.1: sleep(random.random() / 10) sleep(2) assert counter == int(client.get(incr_key)), 'Incr failed!' quickstop()