我已爲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