Skip to content

Redis Provider

After you've added the Redis Provider package to your project, setting the provider up in code is easy.

Add to Droplet

First, register the RedisProvider.Provider with your Droplet.

import Vapor
import RedisProvider

let config = try Config()
try config.addProvider(RedisProvider.Provider.self)

let drop = try Droplet(config)


Configure Vapor

Once the provider is added to your Droplet, you can configure Vapor to use Redis for caching.


    "cache": "redis"


Learn more about configuration files in the Settings guide.

Configure Redis

If you run your application now, you will likely see an error that the Redis configuration file is missing. Let's add that now.


Here is an example of a simple Redis configuration file.


    "hostname": "",
    "port": 6379,
    "password": "secret",
    "database": 2

Both password and database are optional.


It's a good idea to store the Redis configuration file in the Config/secrets folder since it may contain sensitive information.


You can also pass the Redis credentials as a URL.


    "url": "redis://:secret@"

Both password and database are optional.


You are now ready to start using Cache with your Redis database.