Inheritance: IRedisSentinel
        public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string masterName)
        {
            this.redisSentinel = redisSentinel;
            this.redisManager  = redisSentinel.RedisManager;
            this.masterName    = masterName;

            //Sentinel Servers doesn't support DB, reset to 0
            var sentinelEndpoint = host.ToRedisEndpoint(defaultPort: RedisNativeClient.DefaultPortSentinel);

            this.sentinelClient = new RedisClient(sentinelEndpoint)
            {
                Db = 0
            };
            this.sentinelPubSubClient = new RedisClient(sentinelEndpoint)
            {
                Db = 0
            };
            this.sentinelSubscription           = this.sentinelPubSubClient.CreateSubscription();
            this.sentinelSubscription.OnMessage = SentinelMessageReceived;

            if (Log.IsDebugEnabled)
            {
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(host));
            }
        }
 public RedisSentinelResolver(RedisSentinel sentinel, IEnumerable<RedisEndpoint> masters, IEnumerable<RedisEndpoint> slaves)
 {
     this.sentinel = sentinel;
     ResetMasters(masters.ToList());
     ResetSlaves(slaves.ToList());
     ClientFactory = RedisConfig.ClientFactory;
 }
Exemple #3
0
 public RedisSentinelResolver(RedisSentinel sentinel, IEnumerable <RedisEndpoint> masters, IEnumerable <RedisEndpoint> slaves)
 {
     this.sentinel = sentinel;
     ResetMasters(masters.ToList());
     ResetSlaves(slaves.ToList());
     ClientFactory = RedisConfig.ClientFactory;
 }
        public void Execute()
        {
            var sentinelHosts = new[] { "127.0.0.1:26380", "127.0.0.1:26381", "127.0.0.1:26382" };
            var sentinel = new RedisSentinel(sentinelHosts, masterName: "mymaster");
            sentinel.HostFilter = host => "password@{0}".Fmt(host);
            var manager = sentinel.Start();

            sentinel.OnWorkerError = exception => Console.WriteLine(exception);

            while (true)
            {
                try
                {
                    const string RedisKey = "my Name";
                    using (var client = manager.GetClient())
                    {
                        var result = client.Get<string>(RedisKey);
                        Console.WriteLine("Redis Key: {0} \t Port: {1}", result, client.Port);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error {0}".Fmt(ex.Message));
                }
                Thread.Sleep(3000);
            }
        } 
        public RedisSentinelWorker(RedisSentinel sentinel, RedisEndpoint sentinelEndpoint)
        {
            this.sentinel = sentinel;
            this.sentinelClient = new RedisClient(sentinelEndpoint) {
                Db = 0, //Sentinel Servers doesn't support DB, reset to 0
                ConnectTimeout = sentinel.SentinelWorkerTimeoutMs,
            };

            if (Log.IsDebugEnabled)
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(sentinelEndpoint));
        }
 protected override RedisSentinel CreateSentinel()
 {
     var sentinel = new RedisSentinel(SentinelHosts)
     {
         IpAddressMap =
         {
             {"127.0.0.1", "10.0.0.9"},
         }
     };
     return sentinel;
 }
        public RedisSentinelWorker(RedisSentinel sentinel, RedisEndpoint sentinelEndpoint)
        {
            this.sentinel = sentinel;

            //Sentinel Servers doesn't support DB, reset to 0
            var timeoutMs = (int) sentinel.SentinelWorkerTimeout.TotalMilliseconds;
            this.sentinelClient = new RedisClient(sentinelEndpoint) { Db = 0, ConnectTimeout = timeoutMs };

            if (Log.IsDebugEnabled)
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(sentinelEndpoint));
        }
        public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string sentinelName)
        {
            this.redisSentinel                  = redisSentinel;
            this.redisManager                   = redisSentinel.redisManager;
            this.sentinelName                   = sentinelName;
            this.sentinelClient                 = new RedisClient(host);
            this.sentinelPubSubClient           = new RedisClient(host);
            this.sentinelSubscription           = this.sentinelPubSubClient.CreateSubscription();
            this.sentinelSubscription.OnMessage = SentinelMessageReceived;

            Log.Info("Set up Redis Sentinel on {0}".Fmt(host));
        }
 protected override RedisSentinel CreateSentinel()
 {
     var sentinel = new RedisSentinel(SentinelHosts, "master")
     {
         IpAddressMap =
         {
             {"10.240.109.243", "130.211.149.172"},
             {"10.240.201.29", "130.211.191.163"},
             {"10.240.200.252", "146.148.61.165"},
         }
     };
     return sentinel;
 }
 protected override RedisSentinel CreateSentinel()
 {
     var sentinel = new RedisSentinel(SentinelHosts, "master")
     {
         IpAddressMap =
         {
             {"10.240.34.152", "146.148.77.31"},
             {"10.240.203.193", "130.211.139.141"},
             {"10.240.209.52", "107.178.218.53"},
         }
     };
     return sentinel;
 }
        public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string sentinelName)
        {

            this.redisSentinel = redisSentinel;
            this.redisManager = redisSentinel.RedisManager;
            this.sentinelName = sentinelName;

            //Sentinel Servers doesn't support DB, reset to 0
            this.sentinelClient = new RedisClient(host) { Db = 0 };
            this.sentinelPubSubClient = new RedisClient(host) { Db = 0 };
            this.sentinelSubscription = this.sentinelPubSubClient.CreateSubscription();
            this.sentinelSubscription.OnMessage = SentinelMessageReceived;

            if (Log.IsDebugEnabled)
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(host));
        }
        public RedisSentinelWorker(RedisSentinel sentinel, RedisEndpoint sentinelEndpoint)
        {
            this.sentinel       = sentinel;
            this.sentinelClient = new RedisClient(sentinelEndpoint)
            {
                Db             = 0, //Sentinel Servers doesn't support DB, reset to 0
                ConnectTimeout = sentinel.SentinelWorkerConnectTimeoutMs,
                ReceiveTimeout = sentinel.SentinelWorkerReceiveTimeoutMs,
                SendTimeout    = sentinel.SentinelWorkerSendTimeoutMs,
            };

            if (Log.IsDebugEnabled)
            {
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(sentinelEndpoint));
            }
        }
        public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string masterName)
        {
            this.redisSentinel = redisSentinel;
            this.redisManager = redisSentinel.RedisManager;
            this.masterName = masterName;

            //Sentinel Servers doesn't support DB, reset to 0
            var sentinelEndpoint = host.ToRedisEndpoint(defaultPort:RedisNativeClient.DefaultPortSentinel);

            this.sentinelClient = new RedisClient(sentinelEndpoint) { Db = 0 };
            this.sentinelPubSubClient = new RedisClient(sentinelEndpoint) { Db = 0 };
            this.sentinelSubscription = this.sentinelPubSubClient.CreateSubscription();
            this.sentinelSubscription.OnMessage = SentinelMessageReceived;

            if (Log.IsDebugEnabled)
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(host));
        }
Exemple #14
0
        public RedisSentinelWorker(RedisSentinel redisSentinel, string host, string sentinelName)
        {
            this.redisSentinel = redisSentinel;
            this.redisManager  = redisSentinel.RedisManager;
            this.sentinelName  = sentinelName;

            //Sentinel Servers doesn't support DB, reset to 0
            this.sentinelClient = new RedisClient(host)
            {
                Db = 0
            };
            this.sentinelPubSubClient = new RedisClient(host)
            {
                Db = 0
            };
            this.sentinelSubscription           = this.sentinelPubSubClient.CreateSubscription();
            this.sentinelSubscription.OnMessage = SentinelMessageReceived;

            if (Log.IsDebugEnabled)
            {
                Log.Debug("Set up Redis Sentinel on {0}".Fmt(host));
            }
        }
 public RedisSentinelResolver(RedisSentinel sentinel)
     : this(sentinel, TypeConstants <RedisEndpoint> .EmptyArray, TypeConstants <RedisEndpoint> .EmptyArray)
 {
 }
Exemple #16
0
 public RedisSentinelResolver(RedisSentinel sentinel, IEnumerable <string> masters, IEnumerable <string> slaves)
     : this(sentinel, masters.ToRedisEndPoints(), slaves.ToRedisEndPoints())
 {
 }
Exemple #17
0
 public RedisSentinelResolver(RedisSentinel sentinel)
     : this(sentinel, new RedisEndpoint[0], new RedisEndpoint[0])
 {
 }
 public RedisSentinelResolver(RedisSentinel sentinel, IEnumerable<string> masters, IEnumerable<string> slaves)
     : this(sentinel, masters.ToRedisEndPoints(), slaves.ToRedisEndPoints()) { }
 public RedisSentinelResolver(RedisSentinel sentinel)
     : this(sentinel, TypeConstants<RedisEndpoint>.EmptyArray, TypeConstants<RedisEndpoint>.EmptyArray) { }
 public RedisSentinelResolver(RedisSentinel sentinel)
     : this(sentinel, new RedisEndpoint[0], new RedisEndpoint[0]) { }
        public void Execute()
        {
            RedisConfig.DisableVerboseLogging = true;
            LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);

            var sentinel = new RedisSentinel(new [] {
                    "127.0.0.1:26380",
                    "127.0.0.1:26381",
                    "127.0.0.1:26382",
                }, "mymaster");

            var redisManager = sentinel.Start();

            using (var client = redisManager.GetClient())
            {
                client.FlushAll();
            }

            using (var client = redisManager.GetClient())
            {
                client.IncrementValue("counter").ToString().Print();
            }

            "Force 'SENTINEL failover mymaster' then press enter...".Print();
            Console.ReadLine();

            try
            {
                using (var client = redisManager.GetClient())
                {
                    client.IncrementValue("counter").ToString().Print();
                }
            }
            catch (Exception ex)
            {
                ex.Message.Print();
            }

            try
            {
                using (var client = redisManager.GetClient())
                {
                    client.IncrementValue("counter").ToString().Print();
                }
            }
            catch (Exception ex)
            {
                ex.Message.Print();
            }

            try
            {
                using (var client = redisManager.GetClient())
                {
                    client.IncrementValue("counter").ToString().Print();
                }
            }
            catch (Exception ex)
            {
                ex.Message.Print();
            }

            Console.ReadLine();
        }