我已为Web应用程序(ASP.NET)实施了Redis服务器(用作数据缓存)。在连接之前检测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现在提供这种功能吗?已经有近四年时间了。 – GaTechThomas