redis C# Windows下測試環境
阿新 • • 發佈:2020-12-10
過一段時間不用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