public RedisCacheService()
 {
     conf = new RedisEndpoint {
         Host = "localhost", Port = 6379, Password = "", RetryTimeout = 1000
     };
     //conf = new RedisEndpoint { Host = _devnotConfig.Value.RedisEndPoint, Port = _devnotConfig.Value.RedisPort, Password = "" };
 }
Beispiel #2
0
        public void Does_set_all_properties_on_Client_using_ClientsManagers()
        {
            var connStr =
                "redis://*****:*****@host:1?ssl=true&db=0&connectTimeout=2&sendtimeout=3&receiveTimeout=4&idletimeoutsecs=5&NamespacePrefix=prefix.";
            var expected = new RedisEndpoint {
                Host            = "host",
                Port            = 1,
                Ssl             = true,
                Client          = "nunit",
                Password        = "******",
                Db              = 0,
                ConnectTimeout  = 2,
                SendTimeout     = 3,
                ReceiveTimeout  = 4,
                IdleTimeoutSecs = 5,
                NamespacePrefix = "prefix."
            };

            using (var pooledManager = new RedisManagerPool(connStr)) {
                AssertClientManager(pooledManager, expected);
            }

            using (var pooledManager = new PooledRedisClientManager(connStr)) {
                AssertClientManager(pooledManager, expected);
            }

            using (var basicManager = new BasicRedisClientManager(connStr)) {
                AssertClientManager(basicManager, expected);
            }
        }
        public RedisCacheHelper()
        {
            var host = ConfigurationManager.AppSettings["redisCacheHost"];
            var port = Convert.ToInt32(ConfigurationManager.AppSettings["redisCachePort"]);

            _redisEndpoint = new RedisEndpoint(host, port);
        }
 public RedisCacheRepository(IConfiguration configuration)
 {
     _configuration      = configuration;
     _redisConfiguration = new RedisEndpoint()
     {
         Host = _configuration["RedisConfig:Host"], Password = _configuration["RedisConfig:Password"], Port = Convert.ToInt32(_configuration["RedisConfig:Port"]), Ssl = Convert.ToBoolean(_configuration["RedisConfig:Ssl"])
     };
 }
Beispiel #5
0
        public Form1()
        {
            InitializeComponent();

            host          = ConfigurationManager.AppSettings.Get("host");
            port          = Convert.ToInt32(ConfigurationManager.AppSettings.Get("port"));
            redisEndpoint = new RedisEndpoint(host, port);
        }
Beispiel #6
0
        public void Can_use_password_with_equals()
        {
            var connString = "127.0.0.1?password="******"p@55w0rd=");

            var config = RedisEndpoint.Create(connString);

            Assert.That(config.Password, Is.EqualTo("p@55w0rd="));
        }
 public RedisCacheService(IConfiguration configuration)
 {
     _configuration      = configuration;
     _redisConfiguration = new RedisEndpoint()
     {
         Host = _configuration["RedisConfig:Host"], Password = _configuration["RedisConfig:Password"], Port = _configuration["RedisConfig:Port"].ToInt()
     };
 }
 public RedisCacheService(IOptions <DevnotConfig> devnotConfig)
 {
     _devnotConfig = devnotConfig;
     conf          = new RedisEndpoint {
         Host = _devnotConfig.Value.RedisEndPoint, Port = _devnotConfig.Value.RedisPort, Password = "", RetryTimeout = 1000
     };
     //conf = new RedisEndpoint { Host = _devnotConfig.Value.RedisEndPoint, Port = _devnotConfig.Value.RedisPort, Password = "" };
 }
Beispiel #9
0
        public RedisEndpoint ToRedisEndpoint()
        {
            RedisEndpoint endpoint = new RedisEndpoint();

            endpoint.Host = Host;
            endpoint.Port = Port;
            endpoint.Db   = DbNumber;
            return(endpoint);
        }
        /// <summary>
        /// Gets the redis client.
        /// </summary>
        /// <returns>Returns Interface of Redis Client</returns>
        private IRedisClient GetRedisClient()
        {
            var redisEndpoint = new RedisEndpoint(this.host, this.port);

            var redisClient = this.redisClientFactory.CreateRedisClient(redisEndpoint);

            redisClient.Db = this.db;

            return(redisClient);
        }
        public RedisCacheService()
        {
            _config = new RedisConfig
            {
                Host       = Shell.GetConfigAs <string>("RedisConfig:Host"),
                Port       = Shell.GetConfigAs <int>("RedisConfig:Port"),
                DatabaseId = GetDatabaseId()
            };

            _endPoint = new RedisEndpoint(_config.Host, _config.Port, null, _config.DatabaseId);
        }
Beispiel #12
0
 public RedisService(IOptions <RedisConfigModel> redisConfig)
 {
     _redisConfig = redisConfig;
     if (_redisConfig != null)
     {
         conf = new RedisEndpoint {
             Host = _redisConfig.Value.RedisEndPoint, Port = _redisConfig.Value.RedisPort, Password = "", RetryTimeout = 1000
         }
     }
     ;
 }
        public RedisCacheProvider(string connect)
        {
            if (!string.IsNullOrEmpty(connect))
            {
                var hostAndPort = connect.Split(':');
                host = hostAndPort[0];
                port = hostAndPort[1];
            }

            _endPoint = new RedisEndpoint(host, Convert.ToInt32(port));
        }
Beispiel #14
0
        private static void AssertClientManager(IRedisClientsManager redisManager, RedisEndpoint expected)
        {
            using var readWrite          = (RedisClient)redisManager.GetClient();
            using var readOnly           = (RedisClient)redisManager.GetReadOnlyClient();
            using var cacheClientWrapper = (RedisClientManagerCacheClient)redisManager.GetCacheClient();
            AssertClient(readWrite, expected);
            AssertClient(readOnly, expected);

            using var cacheClient = (RedisClient)cacheClientWrapper.GetClient();
            AssertClient(cacheClient, expected);
        }
Beispiel #15
0
        public void UpdateItem(Item item)
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                IRedisTypedClient <Item> itemClient = client.As <Item>();
                IRedisList <Item>        itemList   = itemClient.Lists["urn:item:" + item.ProductID];

                var index = itemList.Select((Value, Index) => new { Value, Index })
                            .Single(p => p.Value.Id == item.Id).Index;

                var toUpdateItem = itemList.First(x => x.Id == item.Id);

                //var index = itemList.IndexOf(toUpdateItem);

                toUpdateItem.Name  = item.Name;
                toUpdateItem.Price = item.Price;

                itemList.RemoveAt(index);
                if (itemList.Count - 1 < index)
                {
                    itemList.Add(toUpdateItem);
                }
                else
                {
                    itemList.Insert(index, toUpdateItem);
                }

                client.RemoveItemFromSortedSet("urn:Rank", item.Name);
                client.AddItemToSortedSet("urn:Rank", item.Name, item.Price);

                //Publis top 5 Ranked Items
                IDictionary <string, double> Data = client.GetRangeWithScoresFromSortedSet("urn:Rank", 0, 4);
                List <Item> RankList = new List <Item>();
                int         counter  = 0;
                foreach (var itm in Data)
                {
                    counter++;
                    RankList.Add(new Item()
                    {
                        Name = itm.Key, Price = (int)itm.Value, Id = counter
                    });
                }

                var itemJson = JsonConvert.SerializeObject(RankList);
                client.PublishMessage("Rank", itemJson);
                //---------------------------------------------
            }
        }
Beispiel #16
0
        public void Can_Parse_Host()
        {
            var hosts     = new[] { "[email protected]:6123" };
            var endPoints = RedisEndpoint.Create(hosts);

            Assert.AreEqual(1, endPoints.Count);
            var ep = endPoints[0];

            Assert.AreEqual("host.com", ep.Host);
            Assert.AreEqual(6123, ep.Port);
            Assert.AreEqual("pass", ep.Password);
        }
Beispiel #17
0
        public void Host_May_Contain_AtChar()
        {
            var hosts     = new[] { "@pa1@ss@localhost:6123" };
            var endPoints = RedisEndpoint.Create(hosts);

            Assert.AreEqual(1, endPoints.Count);
            var ep = endPoints[0];

            Assert.AreEqual("@pa1@ss", ep.Password);
            Assert.AreEqual("localhost", ep.Host);
            Assert.AreEqual(6123, ep.Port);
        }
Beispiel #18
0
        public ActionResult Counter()
        {
            var           host          = ConfigurationManager.AppSettings["host"].ToString();
            var           port          = Convert.ToInt32(ConfigurationManager.AppSettings["port"]);
            RedisEndpoint redisEndpoint = new RedisEndpoint(host, port);

            using (var client = new RedisClient(redisEndpoint))
            {
                ViewBag.Visit = client.Increment("Website_Counter", 1);
            }

            return(View());
        }
Beispiel #19
0
        public RedisCacheManager()
        {
            var configuration = (IConfiguration)ServiceTool.ServiceProvider.GetService(typeof(IConfiguration));

            var redisConnectionInfo = configuration.GetValue <string>("RedisHostInformation").Split(':');

            if (redisConnectionInfo.Length != 2 || int.TryParse(redisConnectionInfo[1], out var port) == false || port == 0)
            {
                throw new NullReferenceException();
            }

            _redisEndpoint = new RedisEndpoint(redisConnectionInfo[0], port);
        }
Beispiel #20
0
        public JsonResult GetProducts()
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                var productClient = client.As <Product>();
                var products      = productClient.GetAll();
                return(Json(products, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            var conf = new RedisEndpoint()
            {
                Host = "127.0.0.1", Port = 6379
            };

            Console.WriteLine("Services Start...");
            using (IRedisClient client = new RedisClient(conf))
            {
                IRedisSubscription sub = null;
                using (sub = client.CreateSubscription())
                {
                    sub.OnMessage += (channel, news) =>
                    {
                        try
                        {
                            News _news = JsonConvert.DeserializeObject <News>(news);
                            Console.WriteLine(_news.Title);

                            //Güncellenecek 1. Redis Server'ı
                            var conf2 = new RedisEndpoint()
                            {
                                Host = "10.211.55.9", Port = 6379
                            };
                            using (IRedisClient clientServer = new RedisClient(conf2))
                            {
                                clientServer.Set <News>("RedisNews", _news);
                            }

                            //Güncellenecek 2. Redis Server'ı
                            var conf3 = new RedisEndpoint()
                            {
                                Host = "192.168.1.234", Port = 6379
                            };
                            using (IRedisClient clientServer2 = new RedisClient(conf3))
                            {
                                clientServer2.Set <News>("RedisNews", _news);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Hata :" + ex.Message);
                        }
                    };
                    sub.SubscribeToChannels(new string[] { "News" });
                }
            }
            Console.ReadLine();
        }
 private static void AssertClient(RedisClient redis, RedisEndpoint expected)
 {
     Assert.That(redis.Host, Is.EqualTo(expected.Host));
     Assert.That(redis.Port, Is.EqualTo(expected.Port));
     Assert.That(redis.Ssl, Is.EqualTo(expected.Ssl));
     Assert.That(redis.Client, Is.EqualTo(expected.Client));
     Assert.That(redis.Password, Is.EqualTo(expected.Password));
     Assert.That(redis.Db, Is.EqualTo(expected.Db));
     Assert.That(redis.ConnectTimeout, Is.EqualTo(expected.ConnectTimeout));
     Assert.That(redis.SendTimeout, Is.EqualTo(expected.SendTimeout));
     Assert.That(redis.ReceiveTimeout, Is.EqualTo(expected.ReceiveTimeout));
     Assert.That(redis.IdleTimeOutSecs, Is.EqualTo(expected.IdleTimeOutSecs));
     Assert.That(redis.NamespacePrefix, Is.EqualTo(expected.NamespacePrefix));
 }
        public RedisEndpoint GetMaster()
        {
            var sentinelWorker = this.GetValidSentinelWorker();
            var host           = sentinelWorker.GetMasterHost(this.MasterName);

            if (this.ScanForOtherSentinels && DateTime.UtcNow - this._lastSentinelsRefresh > this.RefreshSentinelHostsAfter)
            {
                this.RefreshActiveSentinels();
            }

            return(host != null
                ? RedisEndpoint.Create(this.HostFilter != null?this.HostFilter(host) : host)
                : null);
        }
Beispiel #24
0
        public void SaveProduct(Product product)
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                var userClient = client.As <Product>();
                product.Id = userClient.GetNextSequence();
                userClient.Store(product);
            }
        }
Beispiel #25
0
        public JsonResult GetItems(int?productID)
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                var itemClient = client.As <Item>();
                var itemList   = itemClient.Lists["urn:item:" + productID];
                var items      = itemList.GetAll();
                return(Json(items, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #26
0
        public IActionResult Dummy()
        {
            var           host          = "redis-server";
            var           port          = Convert.ToInt32("6379");
            RedisEndpoint redisEndpoint = new RedisEndpoint(host, port);

            using (var client = new RedisClient(redisEndpoint))
            {
                ViewBag.Visit = client.Increment("Website_Counter", 1);
                // session["pagehit"] = ViewBag.Visit;
                // ViewBag.tempvar = client.IncrBy("testvar", 5);
            }

            return(View());
        }
        private static void AssertClientManager(IRedisClientsManager redisManager, RedisEndpoint expected)
        {
            using (var readWrite = (RedisClient) redisManager.GetClient())
            using (var readOnly = (RedisClient) redisManager.GetReadOnlyClient())
            using (var cacheClientWrapper = (RedisClientManagerCacheClient) redisManager.GetCacheClient())
            {
                AssertClient(readWrite, expected);
                AssertClient(readOnly, expected);

                using (var cacheClient = (RedisClient) cacheClientWrapper.GetClient())
                {
                    AssertClient(cacheClient, expected);
                }
            }
        }
Beispiel #28
0
        public JsonResult GetEditItem(int ProductID, int Id)
        {
            var conf = new RedisEndpoint()
            {
                Host = "xxxxxxxxxxxxxx.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
            };

            using (IRedisClient client = new RedisClient(conf))
            {
                var itemClient   = client.As <Item>();
                var itemList     = itemClient.Lists["urn:item:" + ProductID];
                var toUpdateItem = itemList.First(x => x.Id == Id);
                return(Json(toUpdateItem, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #29
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
            await Task.Delay(1000, stoppingToken);

            var conf = new RedisEndpoint()
            {
                Host = "****.redis.cache.windows.net", Port = 6379, Password = "******"
            };

            Console.WriteLine("Services Start...");
            using (IRedisClient client = new RedisClient(conf))
            {
                IRedisSubscription sub = null;
                using (sub = client.CreateSubscription())
                {
                    sub.OnMessage += (channel, exchange) =>
                    {
                        try
                        {
                            ExchangeModel _exchange = JsonConvert.DeserializeObject <ExchangeModel>(exchange);
                            Console.WriteLine(_exchange.Name + ": " + _exchange.Value);

                            //Redis UPDATE
                            using (IRedisClient clientServer = new RedisClient(conf))
                            {
                                string redisKey = "Exchange:" + _exchange.ID;
                                clientServer.Set <ExchangeModel>(redisKey, _exchange);
                            }

                            //Sql UPDATE
                            using (BlackJackContext context = new BlackJackContext())
                            {
                                var exchangeModel = context.Exchange.FirstOrDefault(ex => ex.Id == _exchange.ID);
                                exchangeModel.Value      = (decimal)_exchange.Value;
                                exchangeModel.UpdateDate = DateTime.Now;
                                context.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    };
                    sub.SubscribeToChannels(new string[] { "Exchange" });
                }
            }
        }
Beispiel #30
0
        public void RedisManagerPool_can_execute_CustomResolver()
        {
            var resolver = new FixedResolver(RedisEndpoint.Create(Config.Sentinel6380), RedisEndpoint.Create(Config.Sentinel6381));

            using (var redisManager = new RedisManagerPool("127.0.0.1:8888")
            {
                RedisResolver = resolver
            }) {
                using (var master = redisManager.GetClient()) {
                    Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380));
                    master.SetValue("KEY", "1");
                }

                using (var master = redisManager.GetClient()) {
                    Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380));
                    master.Increment("KEY", 1);
                }

                Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1));

                for (var i = 0; i < 5; i++)
                {
                    using (var slave = redisManager.GetReadOnlyClient()) {
                        Assert.That(slave.GetHostString(), Is.EqualTo(Config.Sentinel6380));
                        Assert.That(slave.GetValue("KEY"), Is.EqualTo("2"));
                    }
                }

                Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1));

                redisManager.FailoverTo("127.0.0.1:9999", "127.0.0.1:9999");

                for (var i = 0; i < 5; i++)
                {
                    using (var master = redisManager.GetClient()) {
                        Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380));
                        Assert.That(master.GetValue("KEY"), Is.EqualTo("2"));
                    }

                    using (var slave = redisManager.GetReadOnlyClient()) {
                        Assert.That(slave.GetHostString(), Is.EqualTo(Config.Sentinel6380));
                        Assert.That(slave.GetValue("KEY"), Is.EqualTo("2"));
                    }
                }

                Assert.That(resolver.NewClientsInitialized, Is.EqualTo(2));
            }
        }
Beispiel #31
0
 protected bool hasDataOnRedis()
 {
     #region conf
     var conf = new RedisEndpoint()
     {
         Host = "*************************.redis.cache.windows.net", Password = "******", Ssl = true, Port = 6380
     };
     #endregion
     using (IRedisClient client = new RedisClient(conf))
     {
         if (client.SearchKeys("flag*").Count == 0)
         {
             return(false);
         }
         return(true);
     }
 }
 public FixedResolver(RedisEndpoint master, RedisEndpoint slave)
 {
     this.master = master;
     this.slave = slave;
 }
 public RedisClient CreateRedisClient(RedisEndpoint config, bool readWrite)
 {
     NewClientsInitialized++;
     return RedisConfig.ClientFactory(config);
 }
 public SerializingRedisClient(RedisEndpoint config)
     : base(config) {}
 public FixedResolver(RedisEndpoint master, RedisEndpoint slave)
 {
     this.master = master;
     this.slave = slave;
     this.ClientFactory = RedisConfig.ClientFactory;
 }
 public RedisClient CreateRedisClient(RedisEndpoint config, bool master)
 {
     NewClientsInitialized++;
     return ClientFactory(config);
 }