Home Explore Blog CI



nixpkgs

1st chunk of `doc/hooks/redis-test-hook.section.md`
fa75b2eef5aa9efa857fa2a2860f42e8ec07ebf4a5dc080b0000000100000389

# `redisTestHook` {#sec-redisTestHook}

This hook starts a Redis server during `checkPhase`. Example:

```nix
{
  stdenv,
  redis,
  redisTestHook,
}:
stdenv.mkDerivation {

  # ...

  nativeCheckInputs = [
    redisTestHook
  ];
}
```

If you use a custom `checkPhase`, remember to add the `runHook` calls:
```nix
{
  checkPhase = ''
    runHook preCheck

    # ... your tests

    runHook postCheck
  '';
}
```

## Variables {#sec-redisTestHook-variables}

The hook logic will read the following variables and set them to a default value if unset or empty.

Exported variables:

- `REDIS_SOCKET`: UNIX domain socket path

Bash-only variables:

 - `redisTestPort`: Port to use by Redis. Defaults to `6379`

Example usage:

```nix
{
  stdenv,
  redis,
  redisTestHook,
}:
stdenv.mkDerivation {

  # ...

  nativeCheckInputs = [
    redisTestHook
  ];

  preCheck = ''
    redisTestPort=6390;
  '';
}
```

Title: redisTestHook: Starting a Redis Server During checkPhase
Summary
The `redisTestHook` provides a way to start a Redis server during the `checkPhase` of a Nix derivation. It automatically sets up the server and exports the `REDIS_SOCKET` variable. Users can customize the Redis port using the `redisTestPort` variable within the `preCheck` hook.