public async Task KeyMethods() { Assert.IsFalse(await _container.DeleteKey("not-exists")); Assert.IsFalse(await _container.KeyExists("not-exists")); var key = _container.GetKey <RedisItem <int> >("intkey"); await key.Set(1); Assert.IsTrue(await _container.KeyExists("intkey")); Assert.IsTrue(await _container.DeleteKey(key.KeyName, false)); }
public async Task Set_WithPrimitiveTypeAndKeyName_ShouldCreateNewKey(TypeCode typeCode, string keyName) { switch (typeCode) { case TypeCode.String: var keyString = container.GetKey <RedisItem <string> >(keyName); await keyString.Set("stringkey-value"); break; case TypeCode.Int32: var keyInt = container.GetKey <RedisItem <int> >(keyName); await keyInt.Set(1); break; case TypeCode.Boolean: var keyBool = container.GetKey <RedisItem <bool> >(keyName); await keyBool.Set(true); break; case TypeCode.Char: var keyChar = container.GetKey <RedisItem <char> >(keyName); await keyChar.Set('A'); break; } Assert.True(await container.KeyExists(keyName)); }
private static RedisHash <string, string[]> SetupRedis(IConfiguration configuration, string dirPath, string function) { var optionsRedis = configuration .GetSection(AppSettingsSections.RedisSection) .Get <RedisOptions>(); var connection = new RedisConnection($"{optionsRedis.Host}:{optionsRedis.Port}, {GlobalConstants.AbortConnect}", dirPath); var container = new RedisContainer(connection, optionsRedis.InstanceName); var data = container.GetKey <RedisHash <string, string[]> >(GlobalConstants.RedisCacheRecords + function); return(data); }