import pyssdb
import random
import time c = pyssdb.Client('192.168.1.250',) chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
digits = ''
def random_generate_string(length):
return ''.join(random.sample(chars, length))
def random_generate_number(length):
if length > len(digits):
digit_list = random.sample(digits, len(digits))
digit_list.append(random.choice(digits))
return ''.join(digit_list)
return ''.join(random.sample(digits, length))
def random_generate_data(num):
c = [num]
phone_num_seed =
def _random_generate_data():
c[] +=
return (
c[],
"last_name_" + str(random.randrange()),
"first_name_" + str(random.randrange()),
random.choice('MF'),
random.randint(, ),
phone_num_seed + c[],
random_generate_string(),
random_generate_string(),
time.strftime("%Y-%m-%d %H:%M:%S")
)
return _random_generate_data #MULTI_HSET
batch_count =
batch_size =
begin_time = time.time()
loop_count=
all_count=
for x in range(loop_count):
batch_count = x * batch_size
all_count=all_count+batch_size
gen_fun = random_generate_data(batch_count)
batch_data = [gen_fun() for x in range(batch_size)] for a in batch_data :
#成功写入数据量:100000个!
#总共耗时(s): 63.21674847602844
c.multi_hset('person_' + str(a[]), 'last_name', a[],'first_name',a[],'Sex',a[],'Age',a[],'Tel',a[],'Memo',a[],'Date',a[])
#print(c.hgetall('person_'+ str(a[])))
print('成功写入数据量:'+str(all_count)+"个!") end_time = time.time()
total_sec = end_time - begin_time
print("总共耗时(s): " + str(total_sec))
c.disconnect()
print('已成功断开链接!')

写在最后:

1、不要过份追求连接池,因为我们的PYTHON一般当脚本使用,不涉及到高并发,多线程,不需要连接池,只有一个连接,连续操作而以,以前的想法是误区,需要高并发使用LUA去!

2、感觉速度还是可以接受的,使用PYTHON就是因为它方便,能快速实现想法,这就够了!

python3生成测试数据,并写入ssdb的更多相关文章

  1. db:seed 更好的生成测试数据

    make:model -m -> 在database/migrations/目录下生成的table表中设置表的字段名和字段类型->在app/目录下对应的模型文件中设置可添加字段 -> ...

  2. Spark2.2+ES6.4.2(三十一):Spark下生成测试数据,并在Spark环境下使用BulkProcessor将测试数据入库到ES

    Spark下生成2000w测试数据(每条记录150列) 使用spark生成大量数据过程中遇到问题,如果sc.parallelize(fukeData, 64);的记录数特别大比如500w,1000w时 ...

  3. Android 建立文件夹、生成文件并写入文本文件内容

    一.首先添加权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">& ...

  4. Powerdesigner中如何生成测试数据

    设计表完成以后,我们需要生成一些测试数据,可以直接更新到数据库中,下面我们就来试试: 第一步:建立需要的Profiles测试文件,[Model]--[Test Data Profiles],如图所示: ...

  5. SQL Server中生成测试数据

    原文:SQL Server中生成测试数据 简介      在实际的开发过程中.很多情况下我们都需要在数据库中插入大量测试数据来对程序的功能进行测试.而生成的测试数据往往需要符合特定规则.虽然可以自己写 ...

  6. 使用Visual Studio给SQL生成测试数据

    参考:http://www.cnblogs.com/CareySon/archive/2012/02/20/2359444.html 使用VS2010的数据生成计划来生成测试数据 以下面两个表来做例子 ...

  7. pt-online-schema-change 测试使用-包含生成测试数据

    pt-online-schema-change 测试使用-包含生成测试数据 # 参考网址: https://www.2cto.com/database/201703/618280.html 一.简要描 ...

  8. 通过 Python_Faker 生成测试数据

    通过 Python_Faker 生成测试数据 一.介绍 在软件需求.开发.测试过程中,有时候需要使用一些测试数据,针对这种情况,我们一般要么使用已有的系统数据,你不可能通过手工来生成(最傻的方法)可能 ...

  9. 使用Hypothesis生成测试数据

    Hypothesis是Python的一个高级测试库.它允许编写测试用例时参数化,然后生成使测试失败的简单易懂的测试数据.可以用更少的工作在代码中发现更多的bug. 安装 pip install hyp ...

随机推荐

  1. java的命名空间

    这个package  me.gacl.websocket相当于.net中的namespace命名空间. import  相当于.net中的using,引用命名空间:

  2. ArcGIS10.2中文版安装和破解教程

    http://jingyan.baidu.com/article/e73e26c0cb5c1324adb6a791.html

  3. css3的counter的用法

    很早之前,计数器仅存在于ul,ol等元素中,如何想给其他元素增加计数,就只能通过list-style-image,或者background-image来实现.不过现在css3增加了counter属性, ...

  4. ES mapping的写入与查看

    Elasticsearch索引mapping的写入.查看与修改 https://blog.csdn.net/napoay/article/details/52012249 首先创建一个索引: curl ...

  5. error C3872: '0x3000': this character is not allowed in an identifier 解决方法

    文章参考地址:http://blog.csdn.net/danxuezx/article/details/5096497 编译时遇到这个错误多半是从网上拷贝一段代码到VS里然后编译时产生的,这是因为拷 ...

  6. [Leetcode] String to integer atoi 字符串转换成整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  7. [Leetcode] count and say 计数和说

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  8. POJ3450 Corporate Identity 【后缀数组】

    Corporate Identity Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 7662   Accepted: 264 ...

  9. [hdu 4417]树状数组+离散化+离线处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 把数字离散化,一个查询拆成两个查询,每次查询一个前缀的和.主要问题是这个数组是静态的,如果带修改 ...

  10. POJ2516:Minimum Cost(最小费用最大流)

    Minimum Cost Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19088   Accepted: 6740 题目链 ...