Redis主从结构主节点执行写入后wait命令对性能的(2)


def redis_concurrence_test(thread_id):
    redis_nodes = [ {'host':'172.18.0.11','port':8888},
                    {'host':'172.18.0.12','port':8888},
                    {'host':'172.18.0.13','port':8888},
                    {'host':'172.18.0.14','port':8888},
                    {'host':'172.18.0.15','port':8888},
                    {'host':'172.18.0.16','port':8888}]
    try:
        redis_conn = StrictRedisCluster(startup_nodes=redis_nodes, password='******')
    except Exception:
        raise Exception
    redis_conn.config_set('cluster-require-full-coverage', 'yes')
    counter = 0
    for i in range(0, 10000):
        counter = counter + 1
        redis_conn.set('key_' + str(thread_id)+'_'+str(counter), 'value_' + str(i))
        #redis_conn.execute_command('wait', 1, 0)
        if counter == 1000:
            print(str(thread_id)+':insert 1000 keys ' + str(str(datetime.datetime.now())))
            counter = 0

if __name__ == '__main__':
    #redis_cluster_write()
    threads = []
    for i in range(10):
        t = threading.Thread(target=redis_concurrence_test, args=(i,))
        threads.append(t)
    begin_time = ctime()
    for t in threads:
        t.setDaemon(True)
        t.start()
    for t in threads:
        t.join()

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/113db6e3c6f35465aeb0aa7e9781d53b.html