2013-08-30 48 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