Skip to content
Latchkey

How to Spin Up a Redis Service for Tests in GitHub Actions

A Redis service container gives tests a real key-value store on localhost:6379; a redis-cli ping health check confirms readiness.

Declare redis under services: with the official redis image, map port 6379, and use redis-cli ping as the health command.

Steps

  • Add services.redis with image: redis:7.
  • Map ports: [6379:6379].
  • Add a redis-cli ping health check expecting PONG.
  • Point your client at redis://localhost:6379.

Workflow

.github/workflows/ci.yml
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      redis:
        image: redis:7
        ports:
          - 6379:6379
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    env:
      REDIS_URL: redis://localhost:6379
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test

Gotchas

  • If you set a password with --requirepass, the health check needs redis-cli -a <pass> ping or it reports NOAUTH.
  • Redis is in-memory, so each job starts empty; do not assume data from a previous run survives.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →