public async Task Can_select_db()
        {
            var redisManager = new BasicRedisClientManager("127.0.0.1");

            await using (var client = await redisManager.GetClientAsync())
            {
                await client.SelectAsync(2);

                await client.SetAsync("db", 2);
            }

            await using (var client = await redisManager.GetClientAsync())
            {
                await client.SelectAsync(3);

                await client.SetAsync("db", 3);
            }

            await using (var client = await redisManager.GetClientAsync())
            {
                await client.SelectAsync(2);

                //((RedisClient)client).ChangeDb(2);
                var db = await client.GetAsync <int>("db");

                Assert.That(db, Is.EqualTo(2));
            }

            redisManager = new BasicRedisClientManager("127.0.0.1?db=3");
            await using (var client = await redisManager.GetClientAsync())
            {
                var db = await client.GetAsync <int>("db");

                Assert.That(db, Is.EqualTo(3));
            }
        }
示例#2
0
        public async Task Can_change_db_for_client_BasicRedisClientManager()
        {
            await using IRedisClientsManagerAsync db1 = new BasicRedisClientManager(1, new string[] { TestConfig.SingleHost });
            await using IRedisClientsManagerAsync db2 = new BasicRedisClientManager(2, new string[] { TestConfig.SingleHost });
            var val  = Environment.TickCount;
            var key  = "test" + val;
            var db1c = await db1.GetClientAsync();

            var db2c = await db2.GetClientAsync();

            try
            {
                await db1c.SetAsync(key, val);

                Assert.That(await db2c.GetAsync <int>(key), Is.EqualTo(0));
                Assert.That(await db1c.GetAsync <int>(key), Is.EqualTo(val));
            }
            finally
            {
                await db1c.RemoveAsync(key);
            }
        }