Пример #1
0
            public override IRedisSocket GetRedisSocket(CommandPacket cmd)
            {
                var slots    = cmd._flagKey.Select(a => GetClusterSlot(a)).Distinct().ToArray();
                var poolkeys = slots.Select(a => _slotCache.TryGetValue(a, out var trykey) ? trykey : null).Distinct().Where(a => a != null).ToArray();

                if (poolkeys.Length > 1)
                {
                    throw new RedisClientException($"Multiple key slot values not equal: {cmd}");
                }
                var poolkey = poolkeys.FirstOrDefault() ?? _ib.GetKeyFirst();

                var pool = _ib.Get(poolkey);

                if (pool.IsAvailable == false)
                {
                    poolkey = _ib.GetKeys(a => a != null && a.IsAvailable).FirstOrDefault();
                    if (string.IsNullOrEmpty(poolkey))
                    {
                        throw new RedisClientException($"All nodes of the cluster failed to connect");
                    }
                    pool = _ib.Get(poolkey);
                }
                var cli      = pool.Get();
                var rds      = cli.Value.Adapter.GetRedisSocket(null);
                var rdsproxy = DefaultRedisSocket.CreateTempProxy(rds, () => pool.Return(cli));

                rdsproxy._pool = pool;
                return(rdsproxy);
            }
Пример #2
0
            public override IRedisSocket GetRedisSocket(CommandPacket cmd)
            {
                var slots    = cmd?._keyIndexes.Select(a => GetClusterSlot(cmd._input[a].ToInvariantCultureToString())).Distinct().ToArray();
                var poolkeys = slots?.Select(a => _slotCache.TryGetValue(a, out var trykey) ? trykey : null).Distinct().Where(a => a != null).ToArray();
                //if (poolkeys.Length > 1) throw new RedisClientException($"CROSSSLOT Keys in request don't hash to the same slot: {cmd}");
                var poolkey = poolkeys?.FirstOrDefault() ?? _ib.GetKeyFirst();

                var pool = _ib.Get(poolkey);

                if (pool.IsAvailable == false)
                {
                    poolkey = _ib.GetKeys(a => a != null && a.IsAvailable).FirstOrDefault();
                    if (string.IsNullOrEmpty(poolkey))
                    {
                        throw new RedisClientException($"All nodes of the cluster failed to connect");
                    }
                    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);
            }