我为我的网页数据库构建了一个进程外缓存。虽然当我尝试用它做某事(Set,Get)时,我收到以下错误:
A task was canceled
这是我的redis缓存代码。任何帮助都会很棒。谢谢
public class RedisCache : ICache
{
private RedisConnection redis;
public RedisCache()
{
redis = new RedisConnection("127.0.0.1");
redis.Open();
}
public object Get(string key)
{
var method = redis.Strings.Get(0, key);
if (method == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream(method.Result);
object obj = bf.Deserialize(ms);
return obj;
}
public void Set(string key, object value)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, value);
redis.Strings.Set(0, key, ms.ToArray());
}
}