{"id":24700,"library":"testcontainers-redis","title":"Testcontainers Redis","description":"Redis module for testcontainers-python, providing lightweight, throwaway Redis instances for integration tests. Current version is 0.0.1rc1. Part of the testcontainers-python ecosystem (v4.x). Release cadence follows the main testcontainers-python library (approximately monthly).","status":"active","version":"0.0.1rc1","language":"python","source_language":"en","source_url":"https://github.com/testcontainers/testcontainers-python","tags":["testcontainers","redis","testing","docker","integration-testing"],"install":[{"cmd":"pip install testcontainers-redis","lang":"bash","label":"Default"}],"dependencies":[{"reason":"Core library; testcontainers-redis depends on testcontainers-core.","package":"testcontainers","optional":false},{"reason":"Python client to interact with Redis container.","package":"redis","optional":false}],"imports":[{"note":"","wrong":"","symbol":"RedisContainer","correct":"from testcontainers.redis import RedisContainer"}],"quickstart":{"code":"from testcontainers.redis import RedisContainer\nimport redis\n\nwith RedisContainer() as redis_container:\n    client = redis.StrictRedis(\n        host=redis_container.get_container_host_ip(),\n        port=redis_container.get_exposed_port(6379)\n    )\n    client.set(\"test\", \"value\")\n    assert client.get(\"test\") == b\"value\"","lang":"python","description":"Creates a Redis container, connects using redis-py, and verifies basic set/get."},"warnings":[{"fix":"Always use get_container_host_ip() and get_exposed_port() instead of hardcoding host/port.","message":"RedisContainer.get_container_host_ip() returns the host IP, not 'localhost', when using default Docker bridge network. Use it for correct connectivity.","severity":"breaking","affected_versions":"all"},{"fix":"Pin to 'testcontainers-redis==0.0.1rc1' in your requirements.","message":"The module is at version 0.0.1rc1 and may have breaking changes before a stable release. Pin to exact version in production tests.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Use 'with RedisContainer() as container:' instead of manual start/stop.","message":"The @deprecated decorator usage in testcontainers-python core means some wait strategies or container methods may be deprecated. Use the context manager pattern (with statement) for resource cleanup.","severity":"deprecated","affected_versions":"4.x"},{"fix":"Add a loop with retries on redis.exceptions.ConnectionError after starting the container.","message":"Container may not be ready immediately; wait strategies are not automatically configured for Redis. Use redis.Redis() with retries or a custom wait strategy.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"pip install testcontainers or pip install testcontainers-redis (which pulls core).","cause":"testcontainers core is missing; testcontainers-redis does not automatically pull testcontainers.","error":"ModuleNotFoundError: No module named 'testcontainers'"},{"fix":"Use 'from testcontainers.redis import RedisContainer'.","cause":"Incorrect import path. testcontainers-redis provides 'from testcontainers.redis import RedisContainer', not 'import testcontainers.redis'.","error":"AttributeError: module 'testcontainers' has no attribute 'redis'"},{"fix":"Use the container's host and port: host = redis_container.get_container_host_ip(); port = redis_container.get_exposed_port(6379).","cause":"Attempting to connect to localhost instead of the container's host IP. The container is not exposed on localhost by default.","error":"redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused."},{"fix":"Start Docker daemon and ensure the user has permissions (e.g., on Linux, add user to docker group).","cause":"Docker is not running or the Python docker client is misconfigured.","error":"docker.errors.DockerException: Error while fetching server API version"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}