-
-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathRedisContainer.cs
More file actions
41 lines (36 loc) · 1.53 KB
/
RedisContainer.cs
File metadata and controls
41 lines (36 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace Testcontainers.Redis;
/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
public sealed class RedisContainer : DockerContainer
{
/// <summary>
/// Initializes a new instance of the <see cref="RedisContainer" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
public RedisContainer(RedisConfiguration configuration)
: base(configuration)
{
}
/// <summary>
/// Gets the Redis connection string.
/// </summary>
/// <returns>The Redis connection string.</returns>
public string GetConnectionString()
{
return new UriBuilder("redis", Hostname, GetMappedPublicPort(RedisBuilder.RedisPort)).Uri.Authority;
}
/// <summary>
/// Executes the Lua script in the Redis container.
/// </summary>
/// <param name="scriptContent">The content of the Lua script to execute.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that completes when the Lua script has been executed.</returns>
public async Task<ExecResult> ExecScriptAsync(string scriptContent, CancellationToken ct = default)
{
var scriptFilePath = string.Join("/", string.Empty, "tmp", Guid.NewGuid().ToString("D"), Path.GetRandomFileName());
await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, fileMode: Unix.FileMode644, ct: ct)
.ConfigureAwait(false);
return await ExecAsync(new[] { "redis-cli", "--eval", scriptFilePath, "0" }, ct)
.ConfigureAwait(false);
}
}