Skip to content

Commit

Permalink
Enhance AbpRedisCahce
Browse files Browse the repository at this point in the history
  • Loading branch information
realLiangshiwei committed Jun 13, 2024
1 parent 556c0ad commit 5857f65
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
Expand All @@ -19,6 +20,8 @@ public class AbpRedisCache : RedisCache, ICacheSupportsMultipleItems
protected static readonly string SlidingExpirationKey;
protected static readonly string DataKey;
protected static readonly long NotPresent;
protected static readonly RedisValue[] HashMembersAbsoluteExpirationSlidingExpirationData;
protected static readonly RedisValue[] HashMembersAbsoluteExpirationSlidingExpiration;

private readonly static FieldInfo SetScriptField;
private readonly static FieldInfo RedisDatabaseField;
Expand All @@ -27,29 +30,29 @@ public class AbpRedisCache : RedisCache, ICacheSupportsMultipleItems
private readonly static MethodInfo MapMetadataMethod;
private readonly static MethodInfo GetAbsoluteExpirationMethod;
private readonly static MethodInfo GetExpirationInSecondsMethod;
private readonly static MethodInfo OnRedisErrorMethod;

protected IDatabase RedisDatabase => GetRedisDatabase()!;
private IDatabase? _redisDatabase;

protected string Instance { get; }
protected RedisKey InstancePrefix { get; }

Check warning on line 35 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L35

Added line #L35 was not covered by tests

static AbpRedisCache()
{
var type = typeof(RedisCache);

RedisDatabaseField = Check.NotNull(type.GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic), nameof(RedisDatabaseField))!;
RedisDatabaseField = Check.NotNull(type.GetField("_cache", BindingFlags.Instance | BindingFlags.NonPublic), nameof(RedisDatabaseField));

SetScriptField = Check.NotNull(type.GetField("_setScript", BindingFlags.Instance | BindingFlags.NonPublic), nameof(SetScriptField))!;
SetScriptField = Check.NotNull(type.GetField("_setScript", BindingFlags.Instance | BindingFlags.NonPublic), nameof(SetScriptField));

ConnectMethod = Check.NotNull(type.GetMethod("Connect", BindingFlags.Instance | BindingFlags.NonPublic), nameof(ConnectMethod))!;
ConnectMethod = Check.NotNull(type.GetMethod("Connect", BindingFlags.Instance | BindingFlags.NonPublic), nameof(ConnectMethod));

ConnectAsyncMethod = Check.NotNull(type.GetMethod("ConnectAsync", BindingFlags.Instance | BindingFlags.NonPublic), nameof(ConnectAsyncMethod))!;
ConnectAsyncMethod = Check.NotNull(type.GetMethod("ConnectAsync", BindingFlags.Instance | BindingFlags.NonPublic), nameof(ConnectAsyncMethod));

MapMetadataMethod = Check.NotNull(type.GetMethod("MapMetadata", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static), nameof(MapMetadataMethod))!;
MapMetadataMethod = Check.NotNull(type.GetMethod("MapMetadata", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static), nameof(MapMetadataMethod));

GetAbsoluteExpirationMethod = Check.NotNull(type.GetMethod("GetAbsoluteExpiration", BindingFlags.Static | BindingFlags.NonPublic), nameof(GetAbsoluteExpirationMethod))!;
GetAbsoluteExpirationMethod = Check.NotNull(type.GetMethod("GetAbsoluteExpiration", BindingFlags.Static | BindingFlags.NonPublic), nameof(GetAbsoluteExpirationMethod));

GetExpirationInSecondsMethod = Check.NotNull(type.GetMethod("GetExpirationInSeconds", BindingFlags.Static | BindingFlags.NonPublic), nameof(GetExpirationInSecondsMethod))!;
GetExpirationInSecondsMethod = Check.NotNull(type.GetMethod("GetExpirationInSeconds", BindingFlags.Static | BindingFlags.NonPublic), nameof(GetExpirationInSecondsMethod));

OnRedisErrorMethod = Check.NotNull(type.GetMethod("OnRedisError", BindingFlags.Instance | BindingFlags.NonPublic), nameof(OnRedisErrorMethod));

AbsoluteExpirationKey = type.GetField("AbsoluteExpirationKey", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!.ToString()!;

Expand All @@ -58,32 +61,29 @@ static AbpRedisCache()
DataKey = type.GetField("DataKey", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!.ToString()!;

NotPresent = type.GetField("NotPresent", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!.To<int>();

HashMembersAbsoluteExpirationSlidingExpirationData = [AbsoluteExpirationKey, SlidingExpirationKey, DataKey];

HashMembersAbsoluteExpirationSlidingExpiration = [AbsoluteExpirationKey, SlidingExpirationKey];
}

public AbpRedisCache(IOptions<RedisCacheOptions> optionsAccessor)
: base(optionsAccessor)
{
Instance = optionsAccessor.Value.InstanceName ?? string.Empty;
}

protected virtual void Connect()
{
if (GetRedisDatabase() != null)
var instanceName = optionsAccessor.Value.InstanceName;
if (!string.IsNullOrEmpty(instanceName))
{
return;
InstancePrefix = (RedisKey)Encoding.UTF8.GetBytes(instanceName);

Check warning on line 76 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L76

Added line #L76 was not covered by tests
}
}

ConnectMethod.Invoke(this, Array.Empty<object>());
protected virtual IDatabase Connect()
{
return (IDatabase)ConnectMethod.Invoke(this, Array.Empty<object>())!;

Check warning on line 82 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L81-L82

Added lines #L81 - L82 were not covered by tests
}

protected virtual async ValueTask<IDatabase> ConnectAsync(CancellationToken token = default)
{
var redisDatabase = GetRedisDatabase();
if (redisDatabase != null)
{
return redisDatabase;
}

return await (ValueTask<IDatabase>)ConnectAsyncMethod.Invoke(this, new object[] { token })!;
}

Expand All @@ -108,9 +108,17 @@ public void SetMany(
IEnumerable<KeyValuePair<string, byte[]>> items,
DistributedCacheEntryOptions options)
{
Connect();
var cache = Connect();

Check warning on line 111 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L111

Added line #L111 was not covered by tests

Task.WaitAll(PipelineSetMany(items, options));
try
{
Task.WaitAll(PipelineSetMany(cache, items, options));
}
catch (Exception ex)
{
OnRedisError(ex, cache);
throw;

Check warning on line 120 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L114-L120

Added lines #L114 - L120 were not covered by tests
}
}

public async Task SetManyAsync(
Expand All @@ -120,9 +128,17 @@ public async Task SetManyAsync(
{
token.ThrowIfCancellationRequested();

await ConnectAsync(token);
var cache = await ConnectAsync(token);

Check warning on line 131 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L131

Added line #L131 was not covered by tests

await Task.WhenAll(PipelineSetMany(items, options));
try
{
await Task.WhenAll(PipelineSetMany(cache, items, options));
}
catch (Exception ex)
{
OnRedisError(ex, cache);
throw;

Check warning on line 140 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L134-L140

Added lines #L134 - L140 were not covered by tests
}
}

public void RefreshMany(
Expand All @@ -146,43 +162,58 @@ public void RemoveMany(IEnumerable<string> keys)
{
keys = Check.NotNull(keys, nameof(keys));

Connect();
var cache = Connect();

Check warning on line 165 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L165

Added line #L165 was not covered by tests

RedisDatabase.KeyDelete(keys.Select(key => (RedisKey)(Instance + key)).ToArray());
try
{
cache.KeyDelete(keys.Select(key => InstancePrefix.Append(key)).ToArray());
}
catch (Exception ex)
{
OnRedisError(ex, cache);
throw;

Check warning on line 174 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L168-L174

Added lines #L168 - L174 were not covered by tests
}
}

public async Task RemoveManyAsync(IEnumerable<string> keys, CancellationToken token = default)
{
keys = Check.NotNull(keys, nameof(keys));

token.ThrowIfCancellationRequested();
await ConnectAsync(token);
var cache = await ConnectAsync(token);

Check warning on line 183 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L183

Added line #L183 was not covered by tests

await RedisDatabase.KeyDeleteAsync(keys.Select(key => (RedisKey)(Instance + key)).ToArray());
try
{
await cache.KeyDeleteAsync(keys.Select(key => InstancePrefix.Append(key)).ToArray());
}
catch (Exception ex)
{
OnRedisError(ex, cache);
throw;

Check warning on line 192 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L186-L192

Added lines #L186 - L192 were not covered by tests
}
}

protected virtual byte[]?[] GetAndRefreshMany(
IEnumerable<string> keys,
bool getData)
{
Connect();
var cache = Connect();

Check warning on line 200 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L200

Added line #L200 was not covered by tests

var keyArray = keys.Select(key => Instance + key).ToArray();
RedisValue[][] results;
var keyArray = keys.Select(key => InstancePrefix.Append( key)).ToArray();

Check warning on line 202 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L202

Added line #L202 was not covered by tests
byte[]?[] bytes;

if (getData)
try
{
results = RedisDatabase.HashMemberGetMany(keyArray, AbsoluteExpirationKey,
SlidingExpirationKey, DataKey);
var results = cache.HashMemberGetMany(keyArray, GetHashFields(getData));

Check warning on line 207 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L207

Added line #L207 was not covered by tests

Task.WaitAll(PipelineRefreshManyAndOutData(cache, keyArray, results, out bytes));

Check warning on line 209 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L209

Added line #L209 was not covered by tests
}
else
catch (Exception ex)

Check warning on line 211 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L211

Added line #L211 was not covered by tests
{
results = RedisDatabase.HashMemberGetMany(keyArray, AbsoluteExpirationKey,
SlidingExpirationKey);
OnRedisError(ex, cache);
throw;

Check warning on line 214 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L213-L214

Added lines #L213 - L214 were not covered by tests
}

Task.WaitAll(PipelineRefreshManyAndOutData(keyArray, results, out var bytes));

return bytes;
}

Expand All @@ -193,29 +224,28 @@ public async Task RemoveManyAsync(IEnumerable<string> keys, CancellationToken to
{
token.ThrowIfCancellationRequested();

await ConnectAsync(token);
var cache = await ConnectAsync(token);

Check warning on line 227 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L227

Added line #L227 was not covered by tests

var keyArray = keys.Select(key => Instance + key).ToArray();
RedisValue[][] results;
var keyArray = keys.Select(key => InstancePrefix.Append(key)).ToArray();

Check warning on line 229 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L229

Added line #L229 was not covered by tests
byte[]?[] bytes;

if (getData)
try
{
results = await RedisDatabase.HashMemberGetManyAsync(keyArray, AbsoluteExpirationKey,
SlidingExpirationKey, DataKey);
var results = await cache.HashMemberGetManyAsync(keyArray, GetHashFields(getData));
await Task.WhenAll(PipelineRefreshManyAndOutData(cache, keyArray, results, out bytes));

Check warning on line 235 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L234-L235

Added lines #L234 - L235 were not covered by tests
}
else
catch (Exception ex)

Check warning on line 237 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L237

Added line #L237 was not covered by tests
{
results = await RedisDatabase.HashMemberGetManyAsync(keyArray, AbsoluteExpirationKey,
SlidingExpirationKey);
OnRedisError(ex, cache);
throw;

Check warning on line 240 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L239-L240

Added lines #L239 - L240 were not covered by tests
}

await Task.WhenAll(PipelineRefreshManyAndOutData(keyArray, results, out var bytes));


return bytes;
}

protected virtual Task[] PipelineRefreshManyAndOutData(
string[] keys,
IDatabase cache,
RedisKey[] keys,
RedisValue[][] results,
out byte[]?[] bytes)
{
Expand All @@ -242,7 +272,7 @@ protected virtual Task[] PipelineRefreshManyAndOutData(
expr = sldExpr;
}

tasks[i] = RedisDatabase.KeyExpireAsync(keys[i], expr);
tasks[i] = cache.KeyExpireAsync(keys[i], expr);

Check warning on line 275 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L275

Added line #L275 was not covered by tests
}
else
{
Expand All @@ -264,6 +294,7 @@ protected virtual Task[] PipelineRefreshManyAndOutData(
}

protected virtual Task[] PipelineSetMany(
IDatabase cache,
IEnumerable<KeyValuePair<string, byte[]>> items,
DistributedCacheEntryOptions options)
{
Expand All @@ -277,14 +308,13 @@ protected virtual Task[] PipelineSetMany(

for (var i = 0; i < itemArray.Length; i++)
{
tasks[i] = RedisDatabase.ScriptEvaluateAsync(GetSetScript(), new RedisKey[] { Instance + itemArray[i].Key },
new RedisValue[]
{
absoluteExpiration?.Ticks ?? NotPresent,
tasks[i] = cache.ScriptEvaluateAsync(GetSetScript(), new RedisKey[] { InstancePrefix.Append(itemArray[i].Key) },
[
absoluteExpiration?.Ticks ?? NotPresent,

Check warning on line 313 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L312-L313

Added lines #L312 - L313 were not covered by tests
options.SlidingExpiration?.Ticks ?? NotPresent,
GetExpirationInSeconds(creationTime, absoluteExpiration, options) ?? NotPresent,
itemArray[i].Value
});
]);

Check warning on line 317 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L317

Added line #L317 was not covered by tests
}

return tasks;
Expand Down Expand Up @@ -317,14 +347,21 @@ protected virtual void MapMetadata(
{
return (DateTimeOffset?)GetAbsoluteExpirationMethod.Invoke(null, new object[] { creationTime, options });
}

private IDatabase? GetRedisDatabase()
protected virtual void OnRedisError(Exception ex, IDatabase cache)
{
return _redisDatabase ??= RedisDatabaseField.GetValue(this) as IDatabase;
OnRedisErrorMethod.Invoke(this, [ex, cache]);

Check warning on line 353 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L353

Added line #L353 was not covered by tests
}

private string GetSetScript()
{
return SetScriptField.GetValue(this)!.ToString()!;
}

private static RedisValue[] GetHashFields(bool getData)
{

Check warning on line 362 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L362

Added line #L362 was not covered by tests
return getData
? HashMembersAbsoluteExpirationSlidingExpirationData
: HashMembersAbsoluteExpirationSlidingExpiration;
}

Check warning on line 366 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisCache.cs#L364-L366

Added lines #L364 - L366 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ public static class AbpRedisExtensions
{
public static RedisValue[][] HashMemberGetMany(
this IDatabase cache,
string[] keys,
params string[] members)
RedisKey[] keys,
RedisValue[] fields)
{
var tasks = new Task<RedisValue[]>[keys.Length];
var fields = members.Select(member => (RedisValue)member).ToArray();
var results = new RedisValue[keys.Length][];

for (var i = 0; i < keys.Length; i++)
{
tasks[i] = cache.HashGetAsync((RedisKey)keys[i], fields);
tasks[i] = cache.HashGetAsync(keys[i], fields);

Check warning on line 19 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisExtensions.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisExtensions.cs#L19

Added line #L19 was not covered by tests
}

for (var i = 0; i < tasks.Length; i++)
Expand All @@ -28,17 +27,16 @@ public static RedisValue[][] HashMemberGetMany(
return results;
}

public static async Task<RedisValue[][]> HashMemberGetManyAsync(
public async static Task<RedisValue[][]> HashMemberGetManyAsync(
this IDatabase cache,
string[] keys,
params string[] members)
RedisKey[] keys,
RedisValue[] fields)
{
var tasks = new Task<RedisValue[]>[keys.Length];
var fields = members.Select(member => (RedisValue)member).ToArray();

for (var i = 0; i < keys.Length; i++)
{
tasks[i] = cache.HashGetAsync((RedisKey)keys[i], fields);
tasks[i] = cache.HashGetAsync(keys[i], fields);

Check warning on line 39 in framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisExtensions.cs

View check run for this annotation

Codecov / codecov/patch

framework/src/Volo.Abp.Caching.StackExchangeRedis/Volo/Abp/Caching/StackExchangeRedis/AbpRedisExtensions.cs#L39

Added line #L39 was not covered by tests
}

return await Task.WhenAll(tasks);
Expand Down

0 comments on commit 5857f65

Please sign in to comment.