Redis and Vapor With Server-Side Swift: Getting Started

Redis and Vapor With Server-Side Swift: Getting Started

Redis is the most popular key-value data store for high-performance storage and caching. In this tutorial, you’ll learn how to add Redis to a Vapor project to cache API responses. You’ll also explore some of the other features of Redis using the command-line interface (CLI).

[…]

Open the Vapor app in Xcode by double-clicking Package.swift. If you’re not using Xcode, open Terminal and navigate into the starter folder. Then type swift build to pull all the dependencies and build the app. The project contains three folders:

[…]

Enter swift run in the command line. On Linux, you may need to type swift run --enable-test-discovery, depending on what flavor and version combination you have.

[…]

Open configure.swift and add Redis to the import statements at the top:

[…]

This tutorial assumes you have the Docker daemon installed and running. See the note at the beginning of this tutorial if you need help. Start a Docker Redis container by entering the following into the command line:

[…]

Return to routes.swift and add Redis to the import statements at the top:

[…]

Edit routes.swift and add this function anywhere outside of routes:

[…]

After reloading the web page a few times, go back to the Redis CLI window and enter:

[…]