2013-08-30 51 views

回答

1

你可以做這樣的事情在你的APPHOST配置方法如下

public override void Configure(Container container) 
{ 
    ... 
    try 
    { 
     var redisManager = new PooledRedisClientManager("localhost:6379"); 
     // do some sort of test to see if we can talk to the redis server 
     var client = redisManager.GetCacheClient(); 
     var fakeKey = "_________test_______"; 
     client.Add(fakeKey, 1); 
     client.Remove(fakeKey); 
        // if it worked register the cacheClient 
     container.Register(c => redisManager.GetCacheClient()).ReusedWithin(ReuseScope.None); 
    } 
    catch (Exception ex) 
    { 
     // fall back to in memory cache 
     // Log some sort of warning here. 
     container.Register<ICacheClient>(c => new MemoryCacheClient()); 
    } 
    ... 
} 
+0

因此,這對啓動很有幫助,但不能解決Redis在服務正常運行期間出現故障的問題。這可能與我在這裏的其他問題有關:http://stackoverflow.com/questions/18618354/how-to-change-cacheclients-at-runtime-in-servicestack – mariocatch