Пример #1
0
        //[Fact]
        //public void TestOpCountByVersionLocal_DownLevel()
        //{
        //    var config = new ConfigurationOptions
        //    {
        //        EndPoints = { { LocalHost } },
        //        DefaultVersion = new Version(2, 6, 0),
        //        CommandMap = CommandMap.Create(
        //            new HashSet<string> { "info" }, false)
        //    };
        //    using (var conn = ConnectionMultiplexer.Connect(config))
        //    {
        //        TestLockOpCountByVersion(conn, 5, false);
        //        TestLockOpCountByVersion(conn, 3, true);
        //        //TestManualLockOpCountByVersion(conn, 5, false);
        //        //TestManualLockOpCountByVersion(conn, 3, true);
        //    }
        //}

        //[Fact]
        //public void TestOpCountByVersionRemote()
        //{
        //    using (var conn = GetRemoteConnection(open: false))
        //    {
        //        TestLockOpCountByVersion(conn, 1, false);
        //        TestLockOpCountByVersion(conn, 1, true);
        //        //TestManualLockOpCountByVersion(conn, 1, false);
        //        //TestManualLockOpCountByVersion(conn, 1, true);
        //    }
        //}
        private void TestLockOpCountByVersion(ConnectionMultiplexer conn, int expected, bool existFirst)
        {
            const int    DB = 0, LockDuration = 30;
            const string Key = "TestOpCountByVersion";

            var db = conn.GetDatabase(DB);

            db.KeyDelete(Key);
            var    newVal      = "us:" + CreateUniqueName();
            string expectedVal = newVal;

            if (existFirst)
            {
                expectedVal = "other:" + CreateUniqueName();
                db.StringSet(Key, expectedVal, TimeSpan.FromSeconds(LockDuration));
            }
            long   countBefore = conn.GetCounters().Interactive.OperationCount;
            var    taken       = db.LockTake(Key, newVal, TimeSpan.FromSeconds(LockDuration));
            long   countAfter  = conn.GetCounters().Interactive.OperationCount;
            string valAfter    = db.StringGet(Key);

            Assert.Equal(!existFirst, taken);                 // lock taken
            Assert.Equal(expectedVal, valAfter);              // taker
            Output.WriteLine("{0} ops before, {1} ops after", countBefore, countAfter);
            Assert.Equal(expected, countAfter - countBefore); // expected ops (including ping)
            // note we get a ping from GetCounters
        }
Пример #2
0
        static public Dictionary <String, Unit> GetUnitData(string hashKey, string strconn)
        {
            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(strconn);
            //var server = redis.GetServer(someServer);
            IDatabase db          = redis.GetDatabase();
            var       RedisResult = db.HashGetAll(hashKey).ToDictionary(
                x => x.Name.ToString(),
                x => JsonConvert.DeserializeObject <Unit>(x.Value.ToString()),
                StringComparer.Ordinal);

            var RedisStatics = redis.GetCounters();
            var RedisConfig  = redis.Configuration;

            redis.Close();
            redis.Dispose();
            return(RedisResult);
        }
Пример #3
0
        static public Dictionary <String, AgencyEvent> GetEventData(string strconn)
        {
            ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(strconn);
            //var server = redis.GetServer(someServer);
            IDatabase db      = redis.GetDatabase();
            var       hashKey = "cad-events";
            var       AgencyEventRedisResult = db.HashGetAll(hashKey).ToDictionary(
                x => x.Name.ToString(),
                x => JsonConvert.DeserializeObject <AgencyEvent>(x.Value.ToString()),
                StringComparer.Ordinal);

            var RedisStatics = redis.GetCounters();
            var RedisConfig  = redis.Configuration;

            redis.Close();
            redis.Dispose();
            return(AgencyEventRedisResult);
            // double RedisTotEvt = db.HashLength(hashKey);
        }
Пример #4
0
        public IServer GetServer()
        {
            var endPoint = _redis.GetCounters().EndPoint;

            return(_redis.GetServer(endPoint));
        }