예제 #1
0
 public InterceptorBeforeEventArgs(RedisClient cli, CommandPacket cmd)
 {
     this.Client  = cli;
     this.Command = cmd;
 }
예제 #2
0
            internal void ResetSentinel()
            {
                if (ResetSentinelFlag != 0)
                {
                    return;
                }
                if (Interlocked.Increment(ref ResetSentinelFlag) != 1)
                {
                    Interlocked.Decrement(ref ResetSentinelFlag);
                    return;
                }
                string masterhostEnd = _masterHost;
                var    allkeys       = _ib.GetKeys().ToList();

                for (int i = 0; i < _sentinels.Count; i++)
                {
                    if (i > 0)
                    {
                        var first = _sentinels.First;
                        _sentinels.RemoveFirst();
                        _sentinels.AddLast(first.Value);
                    }

                    try
                    {
                        using (var sentinelcli = new RedisSentinelClient(_sentinels.First.Value))
                        {
                            var masterhost             = sentinelcli.GetMasterAddrByName(_connectionString.Host);
                            var masterConnectionString = localTestHost(masterhost, RoleType.Master);
                            if (masterConnectionString == null)
                            {
                                continue;
                            }
                            masterhostEnd = masterhost;

                            if (_rw_splitting)
                            {
                                foreach (var slave in sentinelcli.Salves(_connectionString.Host))
                                {
                                    ConnectionStringBuilder slaveConnectionString = localTestHost($"{slave.ip}:{slave.port}", RoleType.Slave);
                                    if (slaveConnectionString == null)
                                    {
                                        continue;
                                    }
                                }
                            }

                            foreach (var sentinel in sentinelcli.Sentinels(_connectionString.Host))
                            {
                                var remoteSentinelHost = $"{sentinel.ip}:{sentinel.port}";
                                if (_sentinels.Contains(remoteSentinelHost))
                                {
                                    continue;
                                }
                                _sentinels.AddLast(remoteSentinelHost);
                            }
                        }
                        break;
                    }
                    catch { }
                }

                foreach (var spkey in allkeys)
                {
                    _ib.TryRemove(spkey, true);
                }
                Interlocked.Exchange(ref _masterHost, masterhostEnd);
                Interlocked.Decrement(ref ResetSentinelFlag);

                ConnectionStringBuilder localTestHost(string host, RoleType role)
                {
                    ConnectionStringBuilder connectionString = _connectionString.ToString();

                    connectionString.Host        = host;
                    connectionString.MinPoolSize = 1;
                    connectionString.MaxPoolSize = 1;
                    using (var cli = new RedisClient(connectionString))
                    {
                        if (cli.Role().role != role)
                        {
                            return(null);
                        }

                        if (role == RoleType.Master)
                        {
                            //test set/get
                        }
                    }
                    connectionString.MinPoolSize = connectionString.MinPoolSize;
                    connectionString.MaxPoolSize = connectionString.MaxPoolSize;

                    _ib.TryRegister(host, () => new RedisClientPool(connectionString, null, TopOwner));
                    allkeys.Remove(host);

                    return(connectionString);
                }
            }
예제 #3
0
 public ConnectedEventArgs(string host, RedisClientPool pool, RedisClient cli)
 {
     this.Host   = host;
     this.Pool   = pool;
     this.Client = cli;
 }
예제 #4
0
 internal PipelineHook(RedisClient cli) : base(new PipelineAdapter(cli))
 {
     this.Serialize   = cli.Serialize;
     this.Deserialize = cli.Deserialize;
 }
예제 #5
0
 internal GetSharingHook(RedisClient cli, BaseAdapter adapter) : base(adapter)
 {
     this.Serialize   = cli.Serialize;
     this.Deserialize = cli.Deserialize;
 }
 public TransactionAdapter(RedisClient cli)
 {
     UseType   = UseType.Transaction;
     _cli      = cli;
     _commands = new List <TransactionCommand>();
 }
예제 #7
0
 internal TransactionHook(RedisClient cli) : base(new TransactionAdapter(cli))
 {
     this.Serialize   = cli.Serialize;
     this.Deserialize = cli.Deserialize;
 }
예제 #8
0
 public ClientSideCachingContext(RedisClient cli, ClientSideCachingOptions options)
 {
     _cli     = cli;
     _options = options ?? new ClientSideCachingOptions();
 }
예제 #9
0
 public static void UseClientSideCaching(this RedisClient cli, ClientSideCachingOptions options)
 {
     new ClientSideCachingContext(cli, options)
     .Start();
 }
예제 #10
0
 public TransactionAdapter(RedisClient topOwner)
 {
     UseType   = UseType.Transaction;
     TopOwner  = topOwner;
     _commands = new List <TransactionCommand>();
 }
예제 #11
0
 /// <summary>
 /// Single inside RedisClient
 /// </summary>
 protected internal RedisClient(RedisClient topOwner, string host, bool ssl, TimeSpan connectTimeout, TimeSpan receiveTimeout, TimeSpan sendTimeout, Action <RedisClient> connected)
 {
     Adapter = new SingleInsideAdapter(topOwner ?? this, this, host, ssl, connectTimeout, receiveTimeout, sendTimeout, connected);
 }
예제 #12
0
파일: PubSub.cs 프로젝트: gywei/FreeRedis
 internal PubSub(RedisClient topOwner)
 {
     _topOwner = topOwner;
 }