示例#1
0
        /// <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));
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <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);
        }
示例#4
0
 /// <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);
 }
示例#5
0
 /// <inheritdoc/>
 public TimeToLiveResult GetTimeToLive(string key)
 {
     var redisResult = GetRetryPolicy().Execute<RedisResult>(() => GetDatabase().ScriptEvaluate(LuaScripts.GetTtlScript(), keys: new RedisKey[] { key }));
     return ConvertRedisResultTimeToLiveResult((int)redisResult);
 }
示例#6
0
        /// <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);
        }
示例#7
0
 /// <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);
 }