創建連接池
1 private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip:port" }, new string[] { "password@ip:port" }); 2 public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts) 3 { 4 //支持讀寫分離,均衡負載 5 return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig 6 { 7 MaxWritePoolSize = 5,//“寫”鏈接池鏈接數 8 MaxReadPoolSize = 5,//“讀”鏈接池鏈接數 9 AutoStart = true, 10 DefaultDb = 0 11 }); 12 }
調用
using (IRedisClient Redis = prcm.GetClient()) {Redis.Set(key, value, dateTime);}
這是會出現錯誤? command role not support for your account
云redis,解決方案:
在創建連接池的時候 加入這樣一句代碼? RedisConfig.VerifyMasterConnections = false;
?
1 public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts) 2 { 3 RedisConfig.VerifyMasterConnections = false; 4 //支持讀寫分離,均衡負載 5 return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig 6 { 7 MaxWritePoolSize = 5,//“寫”鏈接池鏈接數 8 MaxReadPoolSize = 5,//“讀”鏈接池鏈接數 9 AutoStart = true, 10 DefaultDb = 0 11 }); 12 }
問題解決!
redis集群自建還是用阿里云。?
另外一個錯誤
NOAUTH Authentication required
解決方法
阿里云可以跑mapreduce嗎、private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip:port" }, new string[] { "password@ip:port" });