Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/modules/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,37 @@ npm install @testcontainers/redis --save-dev
## Examples

<!--codeinclude-->

[Start container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startContainer

<!--/codeinclude-->

<!--codeinclude-->

[Connect redis client to container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:simpleConnect

<!--/codeinclude-->

<!--codeinclude-->

[Start container with password authentication:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startWithCredentials

<!--/codeinclude-->

<!--codeinclude-->

[Define volume for persistent/predefined data:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:persistentData

<!--/codeinclude-->

<!--codeinclude-->

[Start container with redis/redis-stack-server image:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startWithRedisStack

<!--/codeinclude-->

<!--codeinclude-->

[Execute a command inside the container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:executeCommand

<!--/codeinclude-->
14 changes: 14 additions & 0 deletions packages/modules/redis/src/redis-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ describe("RedisContainer", { timeout: 240_000 }, () => {
});
// }

// startWithRedisStack {
it("should start with redis-stack-server and json module", async () => {
const container = await new RedisContainer("redis/redis-stack-server:latest").withPassword("testPassword").start();
const client = await connectTo(container);

await client.json.set("key", "$", { name: "test" });
const result = await client.json.get("key");
expect(result).toEqual({ name: "test" });

await client.disconnect();
await container.stop();
});
// }

// simpleConnect {
async function connectTo(container: StartedRedisContainer) {
const client = createClient({
Expand Down
14 changes: 10 additions & 4 deletions packages/modules/redis/src/redis-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ export class RedisContainer extends GenericContainer {
}

public override async start(): Promise<StartedRedisContainer> {
this.withCommand([
"redis-server",
...(this.password ? [`--requirepass "${this.password}"`] : []),
const redisArgs = [
...(this.password ? [`--requirepass ${this.password}`] : []),
...(this.persistenceVolume ? ["--save 1 1 ", "--appendonly yes"] : []),
]);
];
if (this.imageName.image.includes("redis-stack")) {
this.withEnvironment({
REDIS_ARGS: redisArgs.join(" "),
}).withEntrypoint(["/entrypoint.sh"]);
} else {
this.withCommand(["redis-server", ...redisArgs]);
}
if (this.persistenceVolume) {
this.withBindMounts([{ mode: "rw", source: this.persistenceVolume, target: "/data" }]);
}
Expand Down