<span style="font-size:18px;">#!/usr/bin/python
import redis
import time
import threading
'''
print "99999999"
redisClient = redis.Redis(host = "127.0.0.1",port = 6379,db = 0)
print "aaaaaaa"
size = 10000
i = 0
print time.ctime()
while i < size:
    redisClient.set('c1','c2')
    i = i +1
print time.ctime()
'''

total_connec_times = 10000*2.5

class Client(threading.Thread):
    def __init__(self,num):
        self.num = 0
        threading.Thread.__init__(self)
        self.RedisClient = redis.Redis(host = "127.0.0.1",port = 6379, db= 0)
    def run(self):
       # print time.ctime()
        while  self.num < total_connec_times:
            self.RedisClient.set('c1','x')
            self.num = self.num + 1
        #print time.ctime()
if __name__ == '__main__':
    thread1 = Client(0)
    thread2 = Client(0)
    thread3 = Client(0)
    thread4 = Client(0)
    print "start time is " +  time.ctime()
    thread1.start();
    thread2.start()
    thread3.start()
    thread4.start()

    thread3.join()
    thread4.join()
    thread2.join()
    thread1.join();
    print "end time is " +  time.ctime()</span>
测试结果并没有redis自带的redis-cli测试结果出众,在4线程情况下(个人电脑配置:AMD A6 1.5GHZ,2G内存)并发量大约10000,如果线程在少或者在多都将降低并发量。
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐