我正在使用ServiceStack.Redis https://servicestack.net/redis存储和检索数据
//Redis Settings
public static IRedisClientsManager GetMgr() {
string sentinalHosts = Helpers.GetRedisSettings("SentinalsHosts");
var sentinelHosts = sentinalHosts.Split(new char[] { ',' },StringSplitOptions.RemoveEmptyEntries);
var sentinel = new RedisSentinel(sentinelHosts, masterName: Helpers.GetRedisSettings("MasterName"));
string settings = string.Format("ConnectTimeout={0}&IdleTimeOutSecs={1}&db={2}", Helpers.GetRedisSettings("ConnectTimeout"),Helpers.GetRedisSettings("IdleTimeOutSecs"),Helpers.GetRedisSettings("db"));
settings = "{0}?" + settings;
sentinel.HostFilter = host => settings.Fmt(host);
sentinel.RedisManagerFactory = (master, slaves) => new RedisManagerPool(master);
return sentinel.Start();
}
//Object that i am storing
public class Test {
public string Id{ get; set; }
public string Value { get; set; }
}
//Method
public void TestData() {
try {
using (var client = RedisHelper.GetMgr().GetClient()) {
var redisUserDefaults = client.As<Test>();
var item = new Test();
item.Id = "1901";
item.Value = "Hello World";
redisUserDefaults.Store(item);
var searchData = redisUserDefaults.SearchKeys("urn:test:*");
}
} catch (Exception ex) {
throw ex;
}
}
当我尝试搜索键时,出现序列化异常
有人可以让我知道如何解决此问题吗?