过一段时间不用Redis再次使用时就会把之前踩的坑再踩一次,只能再记录一次!
1、windows本地环境建立
下载地址
客户端
https://forspeed.rbread05.cn/down/89042_20170622172520.zip
服务端
https://github.com/microsoftarchive/redis/releases/download/win-3.0.504/Redis-x64-3.0.504.zip
2、建立一个控制台应用
安装这个nuget应用
3、控制台代码
RedisClient redisClient = new RedisClient(new RedisEndpoint("localhost", 6379)); DataTable dataTable = new DataTable(); dataTable.Columns.Add("aaa"); DaTarow daTarow = dataTable.NewRow(); daTarow["aaa"] = "张三"; dataTable.Rows.Add(daTarow); //redisClient.Add<byte[]>("tttt",JsonConvert.SerializeObject(dataTable).ToUtf8Bytes()); //var bb1 = redisClient.Get<byte[]>("tttt"); //var bb2=bb1.FromUtf8Bytes(); //var bb3 = JsonConvert.DeserializeObject<DataTable>(bb2); redisClient.Add<string>("bbbb", JsonConvert.SerializeObject(dataTable)); // var bb4 = JsonConvert.DeserializeObject<DataTable>(""); //redisClient.Add<DataTable>("qqq", dataTable); //redisClient.Add<string?>("bbbb11", null); DataTable v = JsonConvert.DeserializeObject<DataTable>(redisClient.Get<string>("bbbb"));
注意两点:
1、DataTable List之类的不能直接写Redis,要通过序列化方式
2、不能直接设置为null