public static void Main() { var client = new AsyncRedisClient(); var connectionSettings = new ConnectionSettings("127.0.0.1", 6379); FailIfException(async() => { Console.WriteLine($"Trying to connect to {connectionSettings.Address}:{connectionSettings.Port}..."); await client.Connect(connectionSettings); Pass(); }).GetAwaiter().GetResult(); FailIfException(async() => { Console.WriteLine("Trying simple write..."); await client.Set(Key, Value); Pass(); }).GetAwaiter().GetResult(); FailIfException(async() => { Console.WriteLine("Trying simple read..."); var result = await client.Get(Key); if (result == Value) { Pass(); } else { Fail("Read incorrect value from the server"); } }).GetAwaiter().GetResult(); FailIfException(async() => { Console.WriteLine("Trying DbSize..."); var result = await client.DbSize(); if (result == 1) { Pass(); } else { Fail("Read incorrect db size from the server"); } }).GetAwaiter().GetResult(); FailIfException(async() => { Console.WriteLine("Trying delete..."); await client.Del(Key); Pass(); }).GetAwaiter().GetResult(); }
public async Task Test_Set_Get() { var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await dut.Set(Key, Value); var res = await dut.Get(Key); Assert.AreEqual(Value, res); }
public async Task TestUnconnectedClient_GetThrowsException() { Exception thrownException = null; var dut = new AsyncRedisClient(); try { await dut.Get(Key); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsInstanceOfType(thrownException, typeof(InvalidOperationException)); }
public async Task Test_ConnectedEvent() { var dut = new AsyncRedisClient(); string result = null; dut.OnConnected += async c => { await c.Set(Key, Value); result = await dut.Get(Key); }; await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); await Task.Delay(1250); Assert.AreEqual(Value, result); }
public async Task TestWrongOperation_GetThrowsException() { Exception thrownException = null; var dut = new AsyncRedisClient(); await dut.Connect(LocalHostDefaultPort.AsConnectionSettings()); try { await dut.SAdd(Key, Value); await dut.Get(Key); } catch (Exception ex) { thrownException = ex; } Assert.IsNotNull(thrownException); Assert.IsInstanceOfType(thrownException, typeof(RedisException)); }