public override IRedisSocket GetRedisSocket(CommandPacket cmd)
            {
                string[] poolkeys = null;
                if (_redirectRule == null)
                {
                    //crc16
                    var slots = cmd?._keyIndexes.Select(a => ClusterAdapter.GetClusterSlot(cmd._input[a].ToInvariantCultureToString())).Distinct().ToArray();
                    poolkeys = slots?.Select(a => _connectionStrings[a % _connectionStrings.Length]).Select(a => $"{a.Host}/{a.Database}").Distinct().ToArray();
                }
                else
                {
                    poolkeys = cmd?._keyIndexes.Select(a => _redirectRule(cmd._input[a].ToInvariantCultureToString())).Distinct().ToArray();
                }

                if (poolkeys == null)
                {
                    poolkeys = new[] { $"{_connectionStrings[0].Host}/{_connectionStrings[0].Database}" }
                }
                ;
                if (poolkeys.Length > 1)
                {
                    throw new RedisClientException($"CROSSSLOT Keys in request don't hash to the same slot: {cmd}");
                }
                var poolkey  = poolkeys?.FirstOrDefault() ?? $"{_connectionStrings[0].Host}/{_connectionStrings[0].Database}";
                var pool     = _ib.Get(poolkey);
                var cli      = pool.Get();
                var rds      = cli.Value.Adapter.GetRedisSocket(null);
                var rdsproxy = DefaultRedisSocket.CreateTempProxy(rds, () => pool.Return(cli));

                rdsproxy._poolkey = poolkey;
                rdsproxy._pool    = pool;
                return(rdsproxy);
            }
Exemple #2
0
 /// <summary>
 /// Cluster RedisClient
 /// </summary>
 public RedisClient(ConnectionStringBuilder[] clusterConnectionStrings)
 {
     Adapter = new ClusterAdapter(this, clusterConnectionStrings);
     Prefix  = clusterConnectionStrings[0].Prefix;
 }