public async Task StringSetAsync(IEnumerable <RedisKeyValue> keyValuePairs, int timeToLiveInSeconds, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var encodedKeysAndValues = new List <IRedisEncodable>(); foreach (var keyValuePair in keyValuePairs) { encodedKeysAndValues.Add(keyValuePair.Key.ToRedisEncoded()); encodedKeysAndValues.Add(keyValuePair.Value.ToRedisEncoded()); } var setCommand = RedisCommand.From(Commands.MSet, encodedKeysAndValues); await SendAndReceiveAsync(setCommand, SuccessResultProcessor, token); var expireCommand = keyValuePairs.Select(keyValuePair => RedisCommand.From(Commands.Expire, keyValuePair.Key.ToRedisEncoded(), timeToLiveInSeconds.ToRedisEncoded())).ToFireAndForgetCommand(); var expireTask = SendAndReceiveAsync(expireCommand, SuccessResultProcessor, token); if (awaitOptions == AwaitOptions.AwaitCompletion) { await expireTask; } }, cancellationToken).ConfigureAwait(false); }
public async ValueTask ExpireAsync(IEnumerable <string> keys, int timeToLiveInSeconds, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var arguments = new List <string> { timeToLiveInSeconds.ToString() }; if (Scripts.MultiExpireScript == null) { Scripts.MultiExpireScript = await Scripts.LoadScript( "for i, name in ipairs(KEYS) do redis.call(\"EXPIRE\", name, ARGV[1]); end", cancellationToken); } var expireTask = Scripts.MultiExpireScript.ExecuteAsync(keys, arguments, cancellationToken); if (awaitOptions == AwaitOptions.AwaitCompletion) { await expireTask; } }, cancellationToken).ConfigureAwait(false); }
public async Task StringSetAsync(IEnumerable <RedisKeyValue> keyValuePairs, int timeToLiveInSeconds, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var redisKeyValues = keyValuePairs.ToList(); var keys = redisKeyValues.Select(value => value.Key).ToList(); var arguments = new List <string> { timeToLiveInSeconds.ToString() }.Concat(redisKeyValues.Select(value => value.Value)); if (Scripts.MultiSetexScript == null) { Scripts.MultiSetexScript = await Scripts.LoadScript( "for i=1, #KEYS do " + "redis.call(\"SETEX\", KEYS[i], ARGV[1], ARGV[i+1]); " + "end", cancellationToken); } var expireTask = Scripts.MultiSetexScript.ExecuteAsync(keys, arguments, cancellationToken); if (awaitOptions == AwaitOptions.AwaitCompletion) { await expireTask; } }, cancellationToken).ConfigureAwait(false); }
public async Task SetGetMultipleKeyWithTtl(AwaitOptions awaitOptions) { var keyValues = new List <RedisKeyValue> { new RedisKeyValue("MultiKeyWithTtl1", "1"), new RedisKeyValue("MultiKeyWithTtl2", "2"), new RedisKeyValue("MultiKeyWithTtl3", "3") }; await(await TomLonghurstRedisClient).StringSetAsync(keyValues, 120, awaitOptions); var redisValues = (await(await TomLonghurstRedisClient).StringGetAsync(new [] { "MultiKeyWithTtl1", "MultiKeyWithTtl2", "MultiKeyWithTtl3" })).ToList(); Assert.That(redisValues.Count, Is.EqualTo(3)); Assert.That(redisValues[0].Value, Is.EqualTo("1")); Assert.That(redisValues[1].Value, Is.EqualTo("2")); Assert.That(redisValues[2].Value, Is.EqualTo("3")); var ttl = await(await TomLonghurstRedisClient).TimeToLiveAsync("MultiKeyWithTtl1"); Assert.That(ttl, Is.LessThanOrEqualTo(120).And.Positive); ttl = await(await TomLonghurstRedisClient).TimeToLiveAsync("MultiKeyWithTtl2"); Assert.That(ttl, Is.LessThanOrEqualTo(120).And.Positive); ttl = await(await TomLonghurstRedisClient).TimeToLiveAsync("MultiKeyWithTtl3"); Assert.That(ttl, Is.LessThanOrEqualTo(120).And.Positive); }
public async Task SetGetMultipleKeyWithTtlMultiple(AwaitOptions awaitOptions) { await SetGetMultipleKeyWithTtl(awaitOptions); await SetGetMultipleKeyWithTtl(awaitOptions); await SetGetMultipleKeyWithTtl(awaitOptions); await SetGetMultipleKeyWithTtl(awaitOptions); await SetGetMultipleKeyWithTtl(awaitOptions); }
private async Task StringSetAsync(RedisKeyValue redisKeyValue, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var command = RedisCommand.From(Commands.Set, redisKeyValue.Key.ToRedisEncoded(), redisKeyValue.Value.ToRedisEncoded()); var task = SendOrQueueAsync(command, SuccessResultProcessor, token); if (awaitOptions == AwaitOptions.AwaitCompletion) { await task; } }, cancellationToken).ConfigureAwait(false); }
public async Task DeleteKeyAsync(IEnumerable <string> keys, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var command = RedisCommand.From(Commands.Del, keys.ToRedisEncoded()); var task = SendAndReceiveAsync(command, IntegerResultProcessor, token); if (awaitOptions == AwaitOptions.AwaitCompletion) { await task; } }, cancellationToken).ConfigureAwait(false); }
private async Task StringSetAsync(RedisKeyValue redisKeyValue, AwaitOptions awaitOptions, CancellationToken cancellationToken) { //CollateMultipleRequestsForPipelining(new Tuple<string, string>(key, value), _stringSetQueue); await RunWithTimeout(async token => { var command = RedisCommand.From(Commands.Set, redisKeyValue.Key.ToRedisEncoded(), redisKeyValue.Value.ToRedisEncoded()); var task = SendAndReceiveAsync(command, SuccessResultProcessor, token); if (awaitOptions == AwaitOptions.AwaitCompletion) { await task; } }, cancellationToken).ConfigureAwait(false); }
public async Task StringSetAsync(IEnumerable <RedisKeyValue> keyValuePairs, AwaitOptions awaitOptions, CancellationToken cancellationToken) { await RunWithTimeout(async token => { var encodedKeysAndValues = new List <IRedisEncodable>(); foreach (var keyValuePair in keyValuePairs) { encodedKeysAndValues.Add(keyValuePair.Key.ToRedisEncoded()); encodedKeysAndValues.Add(keyValuePair.Value.ToRedisEncoded()); } var command = RedisCommand.From(Commands.MSet, encodedKeysAndValues); var task = SendAndReceiveAsync(command, SuccessResultProcessor, token); if (awaitOptions == AwaitOptions.AwaitCompletion) { await task; } }, cancellationToken).ConfigureAwait(false); }
public ValueTask ExpireAsync(IEnumerable <string> keys, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(ExpireAsync(keys, timeToLiveInSeconds, awaitOptions, new CancellationToken())); }
public Task DeleteKeyAsync(IEnumerable <string> keys, AwaitOptions awaitOptions) { return(DeleteKeyAsync(keys, awaitOptions, CancellationToken.None)); }
public Task DeleteKeyAsync(string key, AwaitOptions awaitOptions, CancellationToken cancellationToken) { return(DeleteKeyAsync(new[] { key }, awaitOptions, cancellationToken)); }
public Task DeleteKeyAsync(string key, AwaitOptions awaitOptions) { return(DeleteKeyAsync(key, awaitOptions, CancellationToken.None)); }
public Task StringSetAsync(string key, string value, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(StringSetAsync(new RedisKeyValue(key, value), awaitOptions)); }
public Task StringSetAsync(IEnumerable <RedisKeyValue> keyValuePairs, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(StringSetAsync(keyValuePairs, timeToLiveInSeconds, awaitOptions, CancellationToken.None)); }
private Task StringSetAsync(RedisKeyValue redisKeyValue, int timeToLiveInSeconds, AwaitOptions awaitOptions) { return(StringSetAsync(redisKeyValue, timeToLiveInSeconds, awaitOptions, CancellationToken.None)); }
public Task StringSetAsync(string key, string value, AwaitOptions awaitOptions, CancellationToken cancellationToken) { return(StringSetAsync(new RedisKeyValue(key, value), awaitOptions, cancellationToken)); }
private Task StringSetAsync(RedisKeyValue redisKeyValue, AwaitOptions awaitOptions) { return(StringSetAsync(redisKeyValue, awaitOptions, CancellationToken.None)); }
public Task StringSetAsync(string key, string value, AwaitOptions awaitOptions) { return(StringSetAsync(new RedisKeyValue(key, value), awaitOptions)); }