最近在使用redis 因为项目访问量较大,所以决定使用两台redis服务器来做负载均衡。采用一致性hash算法将缓存存储到这两台服务器上去。如何才能获取想要的阶段进行set 和get操作。
/// <summary> /// 缓冲池 /// </summary> /// <param name="readWriteHosts"></param> /// <param name="readOnlyHosts"></param> /// <returns></returns> public static PooledRedisClientManager CreateManager( string[] readWriteHosts, string[] readOnlyHosts) { return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig { MaxWritePoolSize = readWriteHosts.Length * 5, MaxReadPoolSize = readOnlyHosts.Length * 5, AutoStart = true, }); }
从这个缓存池里面,我如何取到到想要的redis服务器。这里好像默认是第一台。
prcm = CreateManager(new string[] { "127.0.0.1:6379" }, new string[] { "127.0.0.1:6379" }); Redis = prcm.GetClient() as RedisClient;
这里的GetClient()方法默认返回的就当前服务器。
prcm = CreateManager(new string[] { "127.0.0.1:6379","127.0.0.1:6378" }, new string[] { "127.0.0.1:6379","127.0.0.1:6378" }); Redis = prcm.GetClient() as RedisClient;
这里默认返回的是6379的服务器,如果我想返回6378应该如何获取。