示例#1
0
        public async Task CountKeys()
        {
            var db1Id = TestConfig.GetDedicatedDB();
            var db2Id = TestConfig.GetDedicatedDB();

            using (var muxer = Create(allowAdmin: true))
            {
                Skip.IfMissingDatabase(muxer, db1Id);
                Skip.IfMissingDatabase(muxer, db2Id);
                var server = GetAnyMaster(muxer);
                server.FlushDatabase(db1Id, CommandFlags.FireAndForget);
                server.FlushDatabase(db2Id, CommandFlags.FireAndForget);
            }
            using (var muxer = Create(defaultDatabase: db2Id))
            {
                Skip.IfMissingDatabase(muxer, db1Id);
                Skip.IfMissingDatabase(muxer, db2Id);
                RedisKey key = Me();
                var      dba = muxer.GetDatabase(db1Id);
                var      dbb = muxer.GetDatabase(db2Id);
                dba.StringSet("abc", "def", flags: CommandFlags.FireAndForget);
                dba.StringIncrement(key, flags: CommandFlags.FireAndForget);
                dbb.StringIncrement(key, flags: CommandFlags.FireAndForget);

                var server = GetAnyMaster(muxer);
                var c0     = server.DatabaseSizeAsync(db1Id);
                var c1     = server.DatabaseSizeAsync(db2Id);
                var c2     = server.DatabaseSizeAsync(); // using default DB, which is db2Id

                Assert.Equal(2, await c0);
                Assert.Equal(1, await c1);
                Assert.Equal(1, await c2);
            }
        }
示例#2
0
        public static int GetDedicatedDB(IConnectionMultiplexer conn = null)
        {
            int db = Interlocked.Increment(ref _db);

            if (conn != null)
            {
                Skip.IfMissingDatabase(conn, db);
            }
            return(db);
        }
示例#3
0
        public void FlushFetchRandomKey()
        {
            using (var conn = Create(allowAdmin: true))
            {
                var dbId = TestConfig.GetDedicatedDB(conn);
                Skip.IfMissingDatabase(conn, dbId);
                var db     = conn.GetDatabase(dbId);
                var prefix = Me();
                conn.GetServer(TestConfig.Current.MasterServerAndPort).FlushDatabase(dbId, CommandFlags.FireAndForget);
                string anyKey = db.KeyRandom();

                Assert.Null(anyKey);
                db.StringSet(prefix + "abc", "def");
                byte[] keyBytes = db.KeyRandom();

                Assert.Equal(prefix + "abc", Encoding.UTF8.GetString(keyBytes));
            }
        }