import com.meicloud.hbase.utils.CreateNameUtil;
import org.junit.Test;
import java.io.*;
/**
* redis 批量导入数据 txt格式文本
*
* @author ex_zhengxd2
* @version 0.1
* @date 2022/11/30 18:13
*/
public class RedisImportTest {
/**
* 格式化成输入字符串
*/
private String getString(String... args) {
StringBuilder sb = new StringBuilder();
sb.append("*").append(args.length).append("\r\n");
for (String arg : args) {
sb.append("$").append(arg.length()).append("\r\n");
sb.append(arg).append("\r\n");
}
return sb.toString();
}
@Test
public void initFile2() {
Long startTime = System.currentTimeMillis();
String file = "E:\\d4.txt";
BufferedWriter w = null;
StringBuilder sb = new StringBuilder();
try {
w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"));
for (int i = 800000; i < 1000000; i++) {
//for (int i = 1; i <= 100; i++) {
if (i / 3 == 0) {
w.flush();
}
sb.setLength(0);
sb.append(this.getString("hmset", "user_profile:user_info:" + i, "name", CreateNameUtil.math() + "", "age", CreateNameUtil.math() + ""));
w.append(sb.toString());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
w.flush();
w.close();
} catch (IOException e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println("耗时: " + (endTime - startTime) / 1000 + " s。");
}
}
09-21
1193

12-03
1633
