public override void OnBeforeEachTest() { base.OnBeforeEachTest(); typedClient = RedisAsync.As <Shipper>(); model = modelFactory.CreateInstance(1); }
public async Task Working_with_int_values() { const string intKey = "intkey"; const int intValue = 1; //STORING AN INT USING THE BASIC CLIENT await using (var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly()) { await redisClient.SetValueAsync(intKey, intValue.ToString()); string strGetIntValue = await redisClient.GetValueAsync(intKey); int toIntValue = int.Parse(strGetIntValue); Assert.That(toIntValue, Is.EqualTo(intValue)); } //STORING AN INT USING THE GENERIC CLIENT await using (var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly()) { //Create a generic client that treats all values as ints: IRedisTypedClientAsync <int> intRedis = redisClient.As <int>(); await intRedis.SetValueAsync(intKey, intValue); var toIntValue = await intRedis.GetValueAsync(intKey); Assert.That(toIntValue, Is.EqualTo(intValue)); } }
public override void OnBeforeEachTest() { base.OnBeforeEachTest(); RedisRaw?.Dispose(); RedisRaw = new RedisClient(TestConfig.SingleHost) { NamespacePrefix = "RedisTypedClientTests:" }; RedisTyped = RedisAsync.As <CacheRecord>(); }
public async Task SetUp() { if (client is object) { await client.DisposeAsync(); client = null; } client = new RedisClient(TestConfig.SingleHost).ForAsyncOnly(); await client.FlushAllAsync(); redis = client.As <T>(); }
public async Task SetUp() { if (client is object) { await client.DisposeAsync(); client = null; } client = new RedisClient(TestConfig.SingleHost); await client.FlushAllAsync(); redis = client.As <T>(); Hash = redis.GetHash <string>(HashId); }
public async Task SetUp() { if (client is object) { await client.DisposeAsync(); client = null; } client = new RedisClient(TestConfig.SingleHost); await client.FlushAllAsync(); redis = client.As <CustomType>(); List = redis.Lists[ListId]; // List2 = redis.Lists[ListId2]; }
public ValueTask ExecuteAsync(IRedisTypedClientAsync <T> client) { try { switch (_asyncReturnCommand) { case null: ExecuteThrowIfSync(); return(default); case Func <IRedisTypedClientAsync <T>, ValueTask> VoidReturnCommandAsync: return(VoidReturnCommandAsync(client)); case Func <IRedisTypedClientAsync <T>, ValueTask <int> > IntReturnCommandAsync: return(IntReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <long> > LongReturnCommandAsync: return(LongReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <double> > DoubleReturnCommandAsync: return(DoubleReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <byte[]> > BytesReturnCommandAsync: return(BytesReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <string> > StringReturnCommandAsync: return(StringReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <byte[][]> > MultiBytesReturnCommandAsync: return(MultiBytesReturnCommandAsync(client).Await()); case Func <IRedisTypedClientAsync <T>, ValueTask <List <string> > > MultiStringReturnCommandAsync: return(MultiStringReturnCommandAsync(client).Await()); case object obj: ExecuteThrowIfSync(); return(default); } } catch (Exception ex) { Log.Error(ex); return(default); // non-async version swallows
public async Task Working_with_int_list_values() { const string intListKey = "intListKey"; var intValues = new List <int> { 2, 4, 6, 8 }; //STORING INTS INTO A LIST USING THE BASIC CLIENT await using (var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly()) { IRedisListAsync strList = redisClient.Lists[intListKey]; //storing all int values in the redis list 'intListKey' as strings await intValues.ForEachAsync(async x => await strList.AddAsync(x.ToString())); //retrieve all values again as strings List <string> strListValues = await strList.ToListAsync(); //convert back to list of ints List <int> toIntValues = strListValues.ConvertAll(x => int.Parse(x)); Assert.That(toIntValues, Is.EqualTo(intValues)); //delete all items in the list await strList.ClearAsync(); } //STORING INTS INTO A LIST USING THE GENERIC CLIENT await using (var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly()) { //Create a generic client that treats all values as ints: IRedisTypedClientAsync <int> intRedis = redisClient.As <int>(); IRedisListAsync <int> intList = intRedis.Lists[intListKey]; //storing all int values in the redis list 'intListKey' as ints await intValues.ForEachAsync(async x => await intList.AddAsync(x)); List <int> toIntListValues = await intList.ToListAsync(); Assert.That(toIntListValues, Is.EqualTo(intValues)); } }
public RedisITypedRedisClientFacadeAsync(IRedisTypedClientAsync <T> redisTypedClient) { this.redisTypedClient = redisTypedClient; }
public async Task Shippers_UseCase() { await using var redisClient = new RedisClient(TestConfig.SingleHost).ForAsyncOnly(); //Create a 'strongly-typed' API that makes all Redis Value operations to apply against Shippers IRedisTypedClientAsync <Shipper> redis = redisClient.As <Shipper>(); //Redis lists implement IList<T> while Redis sets implement ICollection<T> var currentShippers = redis.Lists["urn:shippers:current"]; var prospectiveShippers = redis.Lists["urn:shippers:prospective"]; await currentShippers.AddAsync( new Shipper { Id = await redis.GetNextSequenceAsync(), CompanyName = "Trains R Us", DateCreated = DateTime.UtcNow, ShipperType = ShipperType.Trains, UniqueRef = Guid.NewGuid() }); await currentShippers.AddAsync( new Shipper { Id = await redis.GetNextSequenceAsync(), CompanyName = "Planes R Us", DateCreated = DateTime.UtcNow, ShipperType = ShipperType.Planes, UniqueRef = Guid.NewGuid() }); var lameShipper = new Shipper { Id = await redis.GetNextSequenceAsync(), CompanyName = "We do everything!", DateCreated = DateTime.UtcNow, ShipperType = ShipperType.All, UniqueRef = Guid.NewGuid() }; await currentShippers.AddAsync(lameShipper); Dump("ADDED 3 SHIPPERS:", await currentShippers.ToListAsync()); await currentShippers.RemoveAsync(lameShipper); Dump("REMOVED 1:", await currentShippers.ToListAsync()); await prospectiveShippers.AddAsync( new Shipper { Id = await redis.GetNextSequenceAsync(), CompanyName = "Trucks R Us", DateCreated = DateTime.UtcNow, ShipperType = ShipperType.Automobiles, UniqueRef = Guid.NewGuid() }); Dump("ADDED A PROSPECTIVE SHIPPER:", await prospectiveShippers.ToListAsync()); await redis.PopAndPushItemBetweenListsAsync(prospectiveShippers, currentShippers); Dump("CURRENT SHIPPERS AFTER POP n' PUSH:", await currentShippers.ToListAsync()); Dump("PROSPECTIVE SHIPPERS AFTER POP n' PUSH:", await prospectiveShippers.ToListAsync()); var poppedShipper = await redis.PopItemFromListAsync(currentShippers); Dump("POPPED a SHIPPER:", poppedShipper); Dump("CURRENT SHIPPERS AFTER POP:", await currentShippers.ToListAsync()); //reset sequence and delete all lists await redis.SetSequenceAsync(0); await redis.RemoveEntryAsync(new[] { currentShippers, prospectiveShippers }); Dump("DELETING CURRENT AND PROSPECTIVE SHIPPERS:", await currentShippers.ToListAsync()); }