2019-05-30 02:21:27 -04:00
---
2020-05-29 14:08:26 -04:00
stage: Verify
group: Runner
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-05-30 02:21:27 -04:00
type: reference
---
2015-12-07 02:39:14 -05:00
# Using Redis
2015-11-25 08:41:14 -05:00
2020-11-23 19:09:13 -05:00
As many applications depend on Redis as their key-value store, you
2015-12-07 02:39:14 -05:00
eventually need it in order for your tests to run. Below you are guided how to
do this with the Docker and Shell executors of GitLab Runner.
2015-11-25 08:41:14 -05:00
2015-12-08 08:59:41 -05:00
## Use Redis with the Docker executor
2015-11-25 08:41:14 -05:00
2015-12-08 14:41:56 -05:00
If you are using [GitLab Runner ](../runners/README.md ) with the Docker executor
you basically have everything set up already.
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
First, in your `.gitlab-ci.yml` add:
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
```yaml
services:
- redis:latest
```
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
Then you need to configure your application to use the Redis database, for
example:
2015-11-25 08:41:14 -05:00
2015-12-08 14:41:56 -05:00
```yaml
2015-12-07 02:39:14 -05:00
Host: redis
```
2015-11-25 08:41:14 -05:00
2020-11-23 19:09:13 -05:00
And that's it. Redis is now available to be used within your testing
2015-12-07 02:39:14 -05:00
framework.
2015-11-25 08:41:14 -05:00
2020-05-27 05:08:30 -04:00
You can also use any other Docker image available on [Docker Hub ](https://hub.docker.com/_/redis ).
2020-08-12 23:10:13 -04:00
For example, to use Redis 6.0 the service becomes `redis:6.0` .
2015-11-25 08:41:14 -05:00
2015-12-08 08:59:41 -05:00
## Use Redis with the Shell executor
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
Redis can also be used on manually configured servers that are using GitLab
Runner with the Shell executor.
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
In your build machine install the Redis server:
2015-11-25 08:41:14 -05:00
2020-01-30 10:09:15 -05:00
```shell
2015-12-07 02:39:14 -05:00
sudo apt-get install redis-server
```
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
Verify that you can connect to the server with the `gitlab-runner` user:
2015-11-25 08:41:14 -05:00
2020-01-30 10:09:15 -05:00
```shell
2018-11-19 08:51:54 -05:00
# Try connecting the Redis server
2015-12-07 02:39:14 -05:00
sudo -u gitlab-runner -H redis-cli
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
# Quit the session
127.0.0.1:6379> quit
```
2015-11-25 08:41:14 -05:00
2015-12-07 02:39:14 -05:00
Finally, configure your application to use the database, for example:
2015-11-25 08:41:14 -05:00
2015-12-08 14:41:56 -05:00
```yaml
2015-12-07 02:39:14 -05:00
Host: localhost
```
## Example project
2019-10-10 23:07:00 -04:00
We have set up an [Example Redis Project ](https://gitlab.com/gitlab-examples/redis ) for your convenience
2015-12-07 02:39:14 -05:00
that runs on [GitLab.com ](https://gitlab.com ) using our publicly available
[shared runners ](../runners/README.md ).
2020-03-13 05:09:23 -04:00
Want to hack on it? Simply fork it, commit and push your changes. Within a few
2020-11-23 19:09:13 -05:00
moments the changes are picked by a public runner and the job begins.