【发布时间】:2011-09-30 06:38:13
【问题描述】:
我已经为 Web 应用程序 (ASP.NET) 实现了一个 Redis 服务器(用作数据缓存)。
其中一个设计目标是在 Redis 服务器出现故障时让 Web 应用程序正常运行。
目前这确实有效,但是它非常非常慢。
以下是处理 Redis 的类中的代码块:
public string GetCachedData(string k)
{
string res = string.Empty;
if (ConfigurationManager.AppSettings.GetValues("UseMemcache")[0].ToString() == "False")
{
return res;
}
try
{
using (RedisClient rs = new RedisClient(ConfigurationManager.AppSettings.GetValues("RedisServerIP")[0].ToString()))
{
byte[] buf = rs.Get(k);
if (buf != null)
{
res = System.Text.ASCIIEncoding.UTF8.GetString(buf);
}
}
}
catch (Exception)
{
res = "";
}
return res;
}
问题:
上线
(RedisClient rs = new RedisClient)
这是应用程序在抛出异常之前会长时间阻塞的地方。
如何做到这一点使其立即抛出?
【问题讨论】:
-
Redis 现在是否提供这种类型的功能?已经快四年了。