/// <inheritdoc/> public void Set(Dictionary<CacheItemDefinition, byte[]> objects) { RedisValue[] values; RedisKey[] keys; GetMultipleSetValues(objects, out keys, out values); foreach (var key in keys) { GetRetryPolicy().Execute(() => GetDatabase().Publish(_setKeyChannel, (string)key)); } GetRetryPolicy().Execute<RedisResult>(() => GetDatabase().ScriptEvaluate(LuaScripts.GetMultipleSetScript(), keys: keys, values: values)); }
/// <inheritdoc/> public async Task<Dictionary<string, TimeToLiveResult>> GetTimeToLivesAsync(string[] keys) { var redisResult = await GetRetryPolicyAsync().ExecuteAsync<RedisResult>(() => GetDatabase().ScriptEvaluateAsync(LuaScripts.GetTtlsScript(), keys: keys.Select(x => (RedisKey)x).ToArray())).ConfigureAwait(false); if (redisResult == null) { throw new InvalidOperationException("Lua script did not return anything."); } return ConvertRedisResultTimeToLiveResults(keys, redisResult); }
/// <inheritdoc/> public Dictionary<string, TimeToLiveResult> GetTimeToLives(string[] keys) { var redisResult = GetRetryPolicy().Execute<RedisResult>(() => GetDatabase().ScriptEvaluate(LuaScripts.GetTtlsScript(), keys: keys.Select(x => (RedisKey)x).ToArray())); if (redisResult == null) { throw new InvalidOperationException("Lua script did not return anything."); } return ConvertRedisResultTimeToLiveResults(keys, redisResult); }
/// <inheritdoc/> public async Task<TimeToLiveResult> GetTimeToLiveAsync(string key) { var redisResult = await GetRetryPolicyAsync().ExecuteAsync<RedisResult>(() => GetDatabase().ScriptEvaluateAsync(LuaScripts.GetTtlScript(), keys: new RedisKey[] { key })).ConfigureAwait(false); return ConvertRedisResultTimeToLiveResult((int)redisResult); }
/// <inheritdoc/> public TimeToLiveResult GetTimeToLive(string key) { var redisResult = GetRetryPolicy().Execute<RedisResult>(() => GetDatabase().ScriptEvaluate(LuaScripts.GetTtlScript(), keys: new RedisKey[] { key })); return ConvertRedisResultTimeToLiveResult((int)redisResult); }
/// <inheritdoc/> public async Task SetAsync(Dictionary<CacheItemDefinition, byte[]> objects) { RedisValue[] values; RedisKey[] keys; GetMultipleSetValues(objects, out keys, out values); foreach (var key in keys) { await GetRetryPolicyAsync().ExecuteAsync(() => GetDatabase().PublishAsync(_setKeyChannel, (string)key)).ConfigureAwait(false); } await GetRetryPolicyAsync().ExecuteAsync<RedisResult>(() => GetDatabase().ScriptEvaluateAsync(LuaScripts.GetMultipleSetScript(), keys: keys, values: values)).ConfigureAwait(false); }
/// <inheritdoc/> public async Task<Dictionary<CacheItemDefinition, byte[]>> GetAsync(ICollection<CacheItemDefinition> keys) { var redisResult = await GetRetryPolicyAsync().ExecuteAsync<RedisResult>(() => GetDatabase().ScriptEvaluateAsync(LuaScripts.GetMultipleGetScript(), keys: keys.Select(x => (RedisKey)x.Key).ToArray())); return CreateCacheItemDefinitionArrayFromLuaScriptResult(keys, redisResult); }