C# 连接redis ,生成1亿个20位长随机数做测试
string buffer = "0123456789";// 随机字符中也可以为汉字(任何) string abc = ""; IRedisClient client = RedisManager.GetClient(); StringBuilder sb = new StringBuilder(20); Random r = new Random(); int range = 10; int iLength = 20; //生成1亿个20位长的数字随机数 DateTime dt = DateTime.Now; for (int k = 0; k <= 100000000; k++) { for (int i = 0; i < iLength; i++) { sb.Append(buffer.Substring(r.Next(range), 1)); } client.AddItemToSet("msfx", sb.ToString()); Console.WriteLine("第{0}个数:{1}", k, sb.ToString()); //清空 sb.Length = 0; } DateTime dt2 = DateTime.Now; Console.WriteLine("执行用时:", dt2, dt); Console.WriteLine("执行用时:", dt2 - dt);
活到老,学到老。