Let's get hands on, clone the application repository from GitHub, start up Redis in a Docker container, and load the sample data!
To get the most from this course, you'll need a machine that can run the application and the Redis server. The application runs directly on your machine and the Redis server runs in a Docker container.
You'll need the following installed on your machine:
- Docker (you'll need the docker-compose command)
- Node.js (use the current Long Term Stable - LTS - version)
- git command line tools
- Your favorite IDE (we like VSCode, but anything you're comfortable with works)
- Postman - we're going to make some API calls and Postman makes that easy.
Clone the course repo from GitHub and install the dependencies:
From the node-js-crash-course directory, start Redis using
The output from the docker ps command should show one container running, using the "redislabs/redismod" image. This container runs Redis 6 with the RediSearch, RedisJSON and RedisBloom modules.
Load the course example data using the provided data loader. This is a Node.js application:
In another terminal window, run the redis-cli executable that's in the Docker container. Then, enter the Redis commands shown at the redis-cli prompt to verify that data loaded successfully:
If you're using RedisInsight, start it up and it should open in your browser automatically. If not, point your browser at http://localhost:8001.
If this is your first time using RedisInsight click "I already have a database".
If you already have other Redis databases configured in RedisInsight, click "Add Redis Database".
Now, click "Connect to a Redis Database Using hostname and port". Configure the database details as shown below, then click "Add Redis Database".
You should now be able to browse your Redis instance. If you need more guidance on how to connect to Redis from RedisInsight, check out Justin's video below but be sure to use 127.0.0.1 as the host, 6379 as the port and leave the username and password fields blank when configuring your database.
Now it's time to start the API Server component of the application and make sure it connects to Redis. This component listens on port 8081.
If port 8081 is in use on your system, edit this section of the
config.json file and pick another available port:
Start the server like this:
This starts the application using nodemon, which monitors for changes in the source code and will restart the server when a change is detected. This will be useful in the next module where you'll be making some code changes.
Ignore the warning about
WEATHER_API_KEY — we'll address this in a later exercise when we look at using Redis as a cache.
To verify that the server is running correctly and connected to Redis, point your browser at:
You should see the summary information for location 200, Katia's Kitchen:
Great! Now you're up and running. Let's move on to the next module and see how we're using Redis Hashes in the application. You'll also get to write some code!
Don't do this now, as we’ve only just started! However, when you do want to shut everything down, here's how to do it...
To stop running redis-cli, simply enter the quit command at the redis-cli prompt:
To stop the Redis Server, make sure you are in the
node-js-crash-course folder that you checked the application repo out to, then:
Redis persists data to the "redisdata" folder. If you want to remove this, just delete it:
To stop each of the application's components, press Ctrl+C in the terminal window that the component is running in. For example, to stop the API server: