Skip to content

Commit

Permalink
Fix for breaking changes in Redis API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-vmware committed Oct 11, 2024
1 parent 8bf9614 commit 3a893de
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,30 @@ private static object GetMockedConnectionMultiplexer(string? connectionString)
databaseMock.Setup(database => database.HashGetAsync(It.IsAny<RedisKey>(), It.IsAny<RedisValue[]>(), It.IsAny<CommandFlags>())).Returns(
(RedisKey key, RedisValue[] _, CommandFlags _) => Task.FromResult(GetRedisValues(key)));

#if NET9_0_OR_GREATER
databaseMock.Setup(database => database.HashSetAsync(It.IsAny<RedisKey>(), It.IsAny<HashEntry[]>(), It.IsAny<CommandFlags>())).Returns(
(RedisKey key, HashEntry[] hashFields, CommandFlags _) =>
{
byte[] data = hashFields[2].Value!;
innerStore[key!] = data;
return Task.CompletedTask;
});
#else
// Use the following for .NET 8 and below.
/*
databaseMock.Setup(database =>
database.ScriptEvaluateAsync(It.IsAny<string>(), It.IsAny<RedisKey[]?>(), It.IsAny<RedisValue[]?>(), It.IsAny<CommandFlags>())).Returns(
(string _, RedisKey[]? keys, RedisValue[]? values, CommandFlags _) => Task.FromResult(SetRedisValues(keys, values)));
(string _, RedisKey[]? keys, RedisValue[]? values, CommandFlags _) =>
{
RedisKey key = keys![0];
byte[] data = values![3]!;
innerStore[key!] = data;
var result = RedisResult.Create(key);
return Task.FromResult(result);
});
*/
#endif

var connectionMultiplexerMock = new Mock<IConnectionMultiplexer>();
connectionMultiplexerMock.Setup(connectionMultiplexer => connectionMultiplexer.Configuration).Returns(connectionString!);
Expand Down Expand Up @@ -139,11 +160,5 @@ RedisValue[] GetRedisValues(RedisKey key)
default
];
}

RedisResult SetRedisValues(RedisKey[]? keys, RedisValue[]? values)
{
innerStore[keys![0]!] = values![3]!;
return RedisResult.Create(keys[0]);
}
}
}

0 comments on commit 3a893de

Please sign in to comment.