ServiceStack.Redis連接阿里雲redis服務時使用連接池出現的問題


創建連接池

 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

解決方案:

在創建連接池的時候 加入這樣一句代碼  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         }

問題解決!

 

另外一個錯誤

NOAUTH Authentication required

解決方法

private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip:port" }, new string[] { "password@ip:port" });


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM