Example #1
0
 public MyCache(string configuration = "127.0.0.1:6379", int db = 0)
 {
     conn    = ConnectionUtils.Connect(configuration);
     this.db = db;
     if (conn == null)
     {
         throw new ArgumentException("It was not possible to connect to redis", "configuration");
     }
 }
Example #2
0
        public void TestNameViaConnect()
        {
            string name = Guid.NewGuid().ToString().Replace("-", "");

            using (var conn = ConnectionUtils.Connect("192.168.0.10,allowAdmin=true,name=" + name))
            {
                Assert.AreEqual(name, conn.Name);
                if (conn.Features.ClientName)
                {
                    var client = conn.Wait(conn.Server.ListClients()).SingleOrDefault(c => c.Name == name);
                    Assert.IsNotNull(client);
                }
            }
        }
 public MyCache(string configuration = "127.0.0.1:6379", int db = 0)
 {
     conn       = ConnectionUtils.Connect(configuration);
     this.db    = db;
     localCache = new MemoryCache("local:" + db.ToString());
     if (conn == null)
     {
         throw new ArgumentException("It was not possible to connect to redis", "configuration");
     }
     sub = conn.GetOpenSubscriberChannel();
     cacheInvalidationChannel = db.ToString() + ":inval";     // note that pub/sub is server-wide; use
                                                              // a channel per DB here
     sub.Subscribe(cacheInvalidationChannel, Invalidate);
 }
Example #4
0
        public void TestNameViaConnect()
        {
            string name = Config.CreateUniqueName();

            using (var conn = ConnectionUtils.Connect(Config.RemoteHost + ",allowAdmin=true,name=" + name))
            {
                Assert.IsNotNull(conn, NO_SERVER, "connection");
                Assert.AreEqual(name, conn.Name, "connection name");
                if (!conn.Features.ClientName)
                {
                    Assert.Inconclusive();
                }
                var client = conn.Wait(conn.Server.ListClients()).SingleOrDefault(c => c.Name == name);
                Assert.IsNotNull(client, "find client");
            }
        }
Example #5
0
        public void TestConnectWithDownedNodeMustBeFast()
        {
            using (var good = ConnectionUtils.Connect(Config.LocalHost + ":6379"))
                using (var bad = ConnectionUtils.Connect(Config.LocalHost + ":6666"))
                {
                    Assert.IsNotNull(good, "6379 should exist for this test");
                    Assert.IsNull(bad, "6666 should not exist for this test");
                }

            StringWriter log   = new StringWriter();
            var          watch = Stopwatch.StartNew();

            using (var selected = ConnectionUtils.Connect(Config.LocalHost + ":6379," + Config.LocalHost + ":6666,name=Core(Q&A)", log))
            {}
            watch.Stop();
            Console.WriteLine(log);
            Assert.Less(1, 2, "I always get this wrong!");
            Assert.Less(watch.ElapsedMilliseconds, 1200, "I always get this wrong!");
        }