Skip to content

Commit

Permalink
fix/redis: fix query error (#185)
Browse files Browse the repository at this point in the history
* feat: Add AppConfig

* refactor: refactor AppConfig

* feat: Initialize Framework configuration

* feat(Configuration): Add Global Configuration

* rename: Masa.EventBus.IntegrationTests rename to Masa.Framework.IntegrationTests.EventBus

* refactor(Configuration): Adjust default variables and default values

* chroe: delete extra space

* fix(redis): fix query error
  • Loading branch information
zhenlei520 authored Aug 9, 2022
1 parent 2cc1f3d commit db20f02
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public async Task<List<string>> GetKeysAsync(string keyPattern)
foreach (var redisResult in arrayRedisResult)
{
var byteArray = (RedisValue[])redisResult.Value;
MapMetadata(byteArray, out DateTimeOffset? absExpr, out TimeSpan? sldExpr, out RedisValue data);
MapMetadataByAutomatic(byteArray, out DateTimeOffset? absExpr, out TimeSpan? sldExpr, out RedisValue data);
func.Invoke(redisResult.Key, absExpr, sldExpr);
dictionary.Add(redisResult.Key, ConvertToValue<T>(data));
}
Expand Down Expand Up @@ -535,7 +535,29 @@ private void RefreshCore(
}
}

private static void MapMetadata(RedisValue[] results, out DateTimeOffset? absoluteExpiration, out TimeSpan? slidingExpiration,
private static void MapMetadata(RedisValue[] results,
out DateTimeOffset? absoluteExpiration,
out TimeSpan? slidingExpiration,
out RedisValue data)
{
absoluteExpiration = null;
slidingExpiration = null;
data = results.Length > 2 ? results[2] : RedisValue.Null;
var absoluteExpirationTicks = (long?)results[0];
if (absoluteExpirationTicks.HasValue && absoluteExpirationTicks.Value != NOT_PRESENT)
{
absoluteExpiration = new DateTimeOffset(absoluteExpirationTicks.Value, TimeSpan.Zero);
}

var slidingExpirationTicks = (long?)results[1];
if (slidingExpirationTicks.HasValue && slidingExpirationTicks.Value != NOT_PRESENT)
{
slidingExpiration = new TimeSpan(slidingExpirationTicks.Value);
}
}

private static void MapMetadataByAutomatic(RedisValue[] results, out DateTimeOffset? absoluteExpiration,
out TimeSpan? slidingExpiration,
out RedisValue data)
{
absoluteExpiration = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,22 @@ public async Task TestGetListByKeyPatternAsyncReturnCountIs1()
Assert.AreEqual(1, dictionary.Count);
Assert.IsTrue(dictionary["test1"] == "test1:Result");
}

[DataTestMethod]
[DataRow("test1", "Result1")]
public async Task TestGetAsyncReturnResult1(string key, string value)
{
_cacheClient.Set(key, value);
var res = await _cacheClient.GetAsync<string>(key);
Assert.AreEqual(value, res);
}

[DataTestMethod]
[DataRow("test1", "Result1")]
public void TestGetReturnResult1(string key, string value)
{
_cacheClient.Set(key, value);
var res = _cacheClient.Get<string>(key);
Assert.AreEqual(value, res);
}
}

0 comments on commit db20f02

Please sign in to comment.