通過C#第三方庫向Redis存儲數據遇到的幾個問題
https://github.com/ServiceStack/ServiceStack.Redis
1、將對象轉json字符串
JsonObject jsonObject=new JsonObject(); jsonObject.Add("aa","年后"); jsonObject.Add("bb","12132"); string str=jsonObject.ToJson(); RedisCacheHelper.Add<object>("test", str, DateTime.Now.AddDays(1)); var v= RedisCacheHelper.Get<object>("test");

不僅多了一個反斜杠,中文還被編碼,如果寫之前加上UrlEncode,讀出時候使用UrlDecode則正常顯示。
例如:
string str =" [\"aaa\",\"bbb\"]"; str= System.Web.HttpUtility.UrlEncode(str); RedisCacheHelper.Add<string>("aa",str,new TimeSpan(1,0,0,0)); string strRet= RedisCacheHelper.Get<string>("aa"); strRet= System.Web.HttpUtility.UrlDecode(strRet);
2、直接使用對象
可以用以下方法,直接傳對象
List<string> list=new List<string>(); list.Add("adfa"); list.Add("bbb"); RedisCacheHelper.Add<object>("test", list, DateTime.Now.AddDays(1) List < string > list1= RedisCacheHelper.Get<List<string>>("test");//默認傳出來的是JArray
3、推薦一個好用的Redis工具

https://github.com/uglide/RedisDesktopManager
