Redis - Lab 1
In this lab session, we will explore Redis by setting up a Docker Redis instance using the provided command. We will cover the following:
- Launching a Docker Redis Instance
- Connecting to the Redis Server
- Basic Redis Commands
1. Starting Redis
Steps
- Start up Docker
- Open your Terminal
-
Execute the following command
Info
This command creates a Docker container named "redis-instance" running the Redis image, maps port 6379 on your host to port 6379 inside the container, and runs Redis in the background.
Expected results
- The terminal will show the container ID
2. Connecting to the Redis Server
Now, let's connect to the Redis server running in the Docker container. You can use the Redis CLI or a Redis client library in your preferred programming language. For this lab, we'll use the Redis CLI.
Steps
- Open the Terminal (or stay in the same Terminal window)
- Execute the following command
Expected results
- Connected to the Redis server where the command line will show
127.0.0.1:6379>
3. Explore the basic Redis commands
Steps
- Execute the list of commands below, expecting its results
Description | Command | Result |
---|---|---|
Set a key-value pair | SET mykey "Hello, Redis!" |
OK |
Retrieve the value of a key | GET mykey |
"Hello, Redis!" |
Increment a key's value | INCR mycounter |
(integer) 1 |
Retrieve the incremented value | GET mycounter |
"1" |
List all keys in the database | KEYS * |
1) "mycounter" 2) "mykey" |