Registry / testing / testcontainers-redis

testcontainers-redis

JSON →
library0.0.1rc1pypypi✓ verified 86d ago

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).

pip install testcontainers-redis
INSTALL
IMPORT
SIG · TESTCONTAINERS-RED
T
testcontainers-redis
testingpythonv0.0.1rc1
Install
3.0s avg
Import
1030ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.1rc1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.112s · 27.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.0s · import 0.948s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedisContainer
from testcontainers.redis import RedisContainer

Creates a Redis container, connects using redis-py, and verifies basic set/get.

from testcontainers.redis import RedisContainer import redis with RedisContainer() as redis_container: client = redis.StrictRedis( host=redis_container.get_container_host_ip(), port=redis_container.get_exposed_port(6379) ) client.set("test", "value") assert client.get("test") == b"value"
Debug
Known issues
breakingRedisContainer.get_container_host_ip() returns the host IP, not 'localhost', when using default Docker bridge network. Use it for correct connectivity.
fix
Always use get_container_host_ip() and get_exposed_port() instead of hardcoding host/port.
affects: all
gotchaThe module is at version 0.0.1rc1 and may have breaking changes before a stable release. Pin to exact version in production tests.
fix
Pin to 'testcontainers-redis==0.0.1rc1' in your requirements.
affects: <1.0.0
deprecatedThe @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.
fix
Use 'with RedisContainer() as container:' instead of manual start/stop.
affects: 4.x
gotchaContainer may not be ready immediately; wait strategies are not automatically configured for Redis. Use redis.Redis() with retries or a custom wait strategy.
fix
Add a loop with retries on redis.exceptions.ConnectionError after starting the container.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'testcontainers'
testcontainers core is missing; testcontainers-redis does not automatically pull testcontainers.
fix
pip install testcontainers or pip install testcontainers-redis (which pulls core).
AttributeError: module 'testcontainers' has no attribute 'redis'
Incorrect import path. testcontainers-redis provides 'from testcontainers.redis import RedisContainer', not 'import testcontainers.redis'.
fix
Use 'from testcontainers.redis import RedisContainer'.
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
Attempting to connect to localhost instead of the container's host IP. The container is not exposed on localhost by default.
fix
Use the container's host and port: host = redis_container.get_container_host_ip(); port = redis_container.get_exposed_port(6379).
docker.errors.DockerException: Error while fetching server API version
Docker is not running or the Python docker client is misconfigured.
fix
Start Docker daemon and ensure the user has permissions (e.g., on Linux, add user to docker group).
Upgrade
Version history
0.0.1rc1latest on PyPI · released Jan 6, 2023
Audit
Dependencies
testcontainersrequiredCore library; testcontainers-redis depends on testcontainers-core.
redisrequiredPython client to interact with Redis container.
Agent activity
21 hits · last 30 days
node
18
Meta
1
OpenAI (training)
1
Resources
testcontainers-redis — pip install testcontainers-redis · libregistry