extras.redis — Redis Database Service


A YellowService for running Redis DB. Runs the official Redis docker image.

Note

Requires the redis extra. For more information, see our installation guide.

class extras.redis.RedisService(docker_client: DockerClient, image: str = 'redis:latest', redis_file: IO[bytes] | None = None, *, container_create_kwargs: dict[str, Any] | None = None, **kwargs)[source]

A service to run the redis database. Inherits from SingleContainerService. Usable with RunMixin and AsyncRunMixin.

Parameters:
  • docker_client – The docker client to used to pull and create the Redis container.

  • image – The image name to create a container of.

  • redis_file – A bytes file object for an RDB file used to load an existing Redis database. For more information read the official redis manual. Defaults to None for a fresh database.

  • container_create_kwargs – Additional keyword arguments passed to docker.models.containers.ContainerCollection.create().

  • **kwargs – Additional keyword arguments passed to SingleContainerService.

Has the following additional methods:

set_rdb(redis_file: IO[bytes])[source]

Load an existing database file onto a redis service.

Parameters:

redis_file

A bytes file object for an RDB file used to load an existing Redis database. For more information read the official redis manual.

Note

Cannot be called while the service is running.

client(*, client_cls=Redis, **kwargs)[source]

Returns a connected Redis client.

Parameters:
  • client_cls – The class or callable to use for the client. Defaults to Redis.

  • **kwargs – Additional keyword arguments passed to the client class.

client_port() int[source]

Returns the port to be used when connecting to the Redis server from the docker host.

reset_state()[source]

Remove all keys from the database.

Equivalent to the redis command FLUSHALL.

set_state(db_dict: Mapping[str, ...])[source]

Set the database to a certain state.

Parameters:

db_dict

A Mapping of string keys used as Redis keys to values. Values can be any of: