void WriteRedisDbIntoFile() { List <string> KeysList; RedisGetAllKeys(out KeysList); //实例化一个文件流--->与写入文件相关联 FileStream fs = new FileStream("keyList123.txt", FileMode.Create); //获得字节数组 string testst = string.Join(",\n", KeysList.ToArray()); byte[] data = new UTF8Encoding().GetBytes(testst); //开始写入 fs.Write(data, 0, data.Length); //清空缓冲区、关闭流 fs.Flush(); fs.Close(); }
public void test2() { string info = @"从前有个人见人爱的小姑娘,喜欢戴着外婆送给她的一顶红色天鹅绒的帽子, 于是大家就叫她小红帽。有一天,母亲叫她给住在森林的外婆送食物,\n 并嘱咐她不要离开大路,走得太远。小红帽在森林中遇见了狼,她从未见过狼, 也不知道狼性凶残,于是把来森林中的目的告诉了狼。狼知道后诱骗小红帽去采野花, 自己跑到林中小屋去把小红帽的外婆吃了。并装成外婆,等小红帽来找外婆时, 狼一口把她吃掉了。后来一个猎人把小红帽和外婆从狼肚里救了出来。"; string err; if (!RedisClient("", "", out err)) { Console.WriteLine(err); } RedisDumpAll(); Random rd = new Random(); for (int i = 0; i < 1000; i++) { DataRedis inputData = new DataRedis(); DateTime dtime = DateTime.Now; inputData.setKeyTime2( (rd.Next(2018, 2020)).ToString(), (rd.Next(1, 12)).ToString(), (rd.Next(1, 31)).ToString(), (rd.Next(1, 24)).ToString(), (rd.Next(1, 60)).ToString(), (rd.Next(1, 60)).ToString(), (rd.Next(1, 1000)).ToString()); inputData.DataJson = i.ToString() + ":" + info; RedisSaveData(inputData, out err); if (err != String.Empty) { Console.WriteLine(err); } } List <string> KeysList; RedisGetAllKeys(out KeysList); DataRedis value; RedisGetData(KeysList[11], out value); //实例化一个文件流--->与写入文件相关联 FileStream fs = new FileStream("keyList123.txt", FileMode.Create); //获得字节数组 string testst = string.Join(",\n", KeysList.ToArray()); byte[] data = new UTF8Encoding().GetBytes(testst); //开始写入 fs.Write(data, 0, data.Length); //清空缓冲区、关闭流 fs.Flush(); fs.Close(); List <string> KeysList2; //RedisGetDataByPattern(@"^2018年3月(\d+)日(\d+)时(\d+)分(\d+)秒(\d+)毫秒", out KeysList2); //RedisGetDataByPattern(@"2018年3月*", out KeysList2); RedisGetDataByPattern(@"(?<=2018)年3月*", out KeysList2); //RedisGetDataByPattern(@"2018*", out KeysList2); Console.Read(); ////Json.NET序列化 //string jsonData = JsonConvert.SerializeObject(lstStuModel); //Console.WriteLine(jsonData); //Console.ReadKey(); ////Json.NET反序列化 //string json = @"{ 'Name':'C#','Age':'3000','ID':'1','Sex':'女'}"; //Student descJsonStu = JsonConvert.DeserializeObject(json);//反序列化 }