Example #1
0
        /// <summary>
        /// 建立redis cluster 本地映射
        /// </summary>
        private void GetClusterMap()
        {
            var clusterNodes = ClusterNodes;

            if (clusterNodes != null && clusterNodes.Any())
            {
                foreach (var item in clusterNodes)
                {
                    if (!RedisConnectionManager.Exsits(item.IPPort))
                    {
                        var cnn = new RedisConnection(item.IPPort);
                        cnn.OnRedirect     += _redisConnection_OnRedirect;
                        cnn.OnDisconnected += _cnn_OnDisconnected;
                        cnn.Connect();
                        if (!string.IsNullOrEmpty(RedisConfig.Passwords))
                        {
                            cnn.Auth(RedisConfig.Passwords);
                        }
                        var isMaster = item.IsMaster;
                        cnn.RedisServerType = isMaster ? RedisServerType.ClusterMaster : RedisServerType.ClusterSlave;
                        RedisConnectionManager.Set(item.IPPort, isMaster, cnn);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 建立redis cluster 本地映射
        /// </summary>
        /// <param name="ipPort"></param>
        private void GetClusterMap(string ipPort)
        {
            var clusterNodes = ClusterNodes;

            RedisConnectionManager.SetClusterNodes(clusterNodes);

            foreach (var item in clusterNodes)
            {
                if (!RedisConnectionManager.Exsits(item.IPPort))
                {
                    var cnn = new RedisConnection(item.IPPort);
                    cnn.Connect();
                    cnn.RedisServerType = item.IsMaster ? RedisServerType.ClusterMaster : RedisServerType.ClusterSlave;
                    RedisConnectionManager.Set(item.IPPort, cnn);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 建立redis cluster 本地映射
        /// </summary>
        /// <param name="ipPort"></param>
        private void GetClusterMap(string ipPort)
        {
            var clusterNodes = ClusterNodes;

            RedisConnectionManager.SetClusterNodes(clusterNodes);

            foreach (var item in clusterNodes)
            {
                if (!RedisConnectionManager.Exsits(item.IPPort))
                {
                    TaskHelper.Start(() =>
                    {
                        var cnn             = new RedisConnection(item.IPPort);
                        cnn.OnRedirect     += _redisConnection_OnRedirect;
                        cnn.OnDisconnected += _cnn_OnDisconnected;
                        cnn.Connect();
                        cnn.RedisServerType = item.IsMaster ? RedisServerType.ClusterMaster : RedisServerType.ClusterSlave;
                        RedisConnectionManager.Set(item.IPPort, cnn);
                    });
                }
            }
        }