PooledRedisClientManager抛出Appharbor Redis URL

时间:2012-08-30 21:33:26

标签: redis servicestack appharbor

我在一个MVC4应用程序中尝试在Appharbor上使用Redis。我正在使用ServiceStack C# client for Redis。使用RedisClient中的ServiceStack.Redis时,一切正常。但是,因为我只打算使用Redis进行缓存,所以我尝试连接ServiceStack提供的ICacheClient作为包装器。这是我的StructureMap配置(https://github.com/ServiceStack/ServiceStack/wiki/Caching):

x.For<IRedisClientsManager>().Use(() => new PooledRedisClientManager(redisUrl));
x.For<ICacheClient>().Use(c => c.GetInstance<IRedisClientsManager>().GetCacheClient());

我的问题是当我使用Appharbor提供的Redis-to-Go网址时,PooledRedisClientManager会抛出错误“input string was not in a correct format”。这是看起来像:

redis://redistogo-appharbor:abunchofrandomcharacters@drum.redistogo.com:9081/

如果我用localhost:5051替换Redis-to-Go网址,一切正常。 我错过了什么?

3 个答案:

答案 0 :(得分:1)

前缀redis://不是任何已知的redis约定 - 它必须是RedisToGo或AppHarbor约定。

ServiceStack的C#RedisClient支持标准的“password @ host:port”约定,例如:

container.Register(c => new PooledRedisClientManager(
    "redistogo-appharbor:abunchofrandomcharacters@drum.redistogo.com:9081"
));

答案 1 :(得分:0)

这样的事情对我有用:

container.Register(c => new PooledRedisClientManager(
    @"abunchofrandomcharacters@drum.redistogo.com:9081"
));

答案 2 :(得分:0)

经过一些试验和错误后,这是有效的。

string redisUrl = ConfigurationManager.AppSettings["REDISTOGO_URL"].Replace("redis://",    "").Replace("redistogo:","").Replace("/", "");
ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
SetConfig(new HostConfig{HandlerFactoryPath = "api"});
container.Register<IRedisClientsManager>(c => new PooledRedisClientManager(redisUrl));
container.Register<IDbRepository>(r => new DbRepository(r.Resolve<IRedisClientsManager>()));