Redis¶
modules::RedisImage → modules::RedisContainer — pinned redis:7.2, port 6379.
Readiness is an in-container redis-cli ping (a log wait races the listener; a raw TCP
probe false-positives through Docker Desktop's host proxy).
Quick start¶
#include "testcontainers/modules/Redis.hpp"
using namespace testcontainers;
const modules::RedisContainer redis = modules::RedisImage().start();
redis.host(); // "localhost" for a local daemon
redis.port(); // the published host port
redis.connection_string(); // "redis://localhost:<port>"
redis.connection_string(3); // "redis://localhost:<port>/3"
Configuration¶
const modules::RedisContainer redis =
modules::RedisImage()
.with_password("s3cr3t") // --requirepass + REDISCLI_AUTH
.with_command_args({"--maxmemory", "64mb"}) // extra redis-server arguments
.start();
// "redis://:s3cr3t@localhost:<port>"
const std::string url = redis.connection_string();
with_password(pw)rendersredis-server --requirepass <pw>and sets container-levelREDISCLI_AUTH, so the readiness probe — and anyredis-cliyouexecyourself — authenticates automatically.with_command_arg/with_command_argsappendredis-serverarguments after--requirepass; argv[0] staysredis-server, so the official entrypoint's protected-mode handling keeps applying.- Redis has no server-side database setter — selection is client-side, via
connection_string(db).
Behavior notes¶
- The module owns the container command (iff a password or args are set) and the
REDISCLI_AUTHenv key — nothing else. PassingREDISCLI_AUTHthroughwith_envalongsidewith_passwordthrows at render time: exec'dredis-clireads the first duplicate of an env key, so no ordering could make the module's entry win. - A Redis config file must be the first server argument, so a config file combined with
with_passwordis unsupported — drop to a customizer'swith_cmdfor full control. - redis-stack, Sentinel, and cluster topologies are out of scope (different image families / multi-container setups).