This repository contains the source code for the RU202 Redis Streams Course at Redis University.
Spotted an error in a text segment, image or video transcript? Please report an issue. We also welcome pull requests with your suggestions. The files for each text segment, image, non-graded quiz question and video transcript can be found in the courseware folder in this repository.
To get the most from this course and follow along with the sample code, you'll need to have access to a Redis 6.2 or 7 server and have Python 3 installed.
In order to run the sample code, you will need:
- Python 3.
- Ability to run the
pipcommand for Python 3. - Access to a local or remote installation of Redis version 6.2 or newer (local preferred). We've provided a Docker Compose file to make this easy for you. If you don't want to use Docker, follow the instructions here to install Redis using a package manager.
If you're using Windows, check out the following resources for help with running Redis:
- Video - Installing Redis on Windows 10
- Redis Blog - Running Redis on Windows 10
- Microsoft - Windows Subsystem for Linux Installation Guide for Windows 10
Execute these commands in your shell to clone the repository, create a Python virtual environment and install the depdendencies:
git clone https://github.com/redislabs-training/ru202.git
cd ru202
python3 -m venv env
. env/bin/activate
pip install -r requirements.txtNote: Ensure you activate your virtual environment in each new shell/terminal session before running any of the sample code.
If you're using Docker to Run Redis, start it like this:
docker-compose up -dYou can now run redis-cli to connect to Redis as follows:
docker exec -it redis_ru202 redis-cliType quit to exit redis-cli back to your shell.
When you are done with the container, you can shut it down like this:
docker-compose downRedis will persist your data to an append only file in the redisdata folder, so it will be there the next time you start the container. To erase it, use rm -rf redisdata.
If you installed Redis using a package manager, start the Redis server if it isn't already running. For example, if you installed Redis with the Homebrew package manager for macOS you'd start it like this:
brew services start redisYou can now run redis-cli to connect to Redis as follows:
docker exec -it redis_ru202 redis-cliType quit to exit redis-cli back to your shell.
When you are done with Redis, you can optionally turn off the server. For example if Redis was installed with the Homebrew package manager for macOS you'd stop the server like this:
brew services stop redisBy default, the code will assume that Redis is available on localhost at port 6379. If your Redis instance is running elsewhere, you will need to set the REDIS_HOST and/or REDIS_PORT environment variables. For example, here's how to configure these to connect to Redis on myredishostname port 6380:
export REDIS_HOST=myredishostname
export REDIS_PORT=6380If your Redis instance requires a password to connect, also set the REDIS_PASSWORD environment variable:
export REDIS_PASSWORD=secret123If you are using Redis 6 or 7 and need to supply a user name when connecting, you should set the REDIS_USER environment variable:
export REDIS_USER=studentTo test your Redis connection and Python environment, run:
python test_connection.pyIf this command outputs True, then you are setup and ready to run the example code as described in the course materials.
Throughout the course, you will be asked to run the example code for the various exercises. Some of these require you to open multiple shell/terminal sessions. Don't forget to start your Python virtual environment in each new shell session. You'll also need to set the environment variables REDIS_HOST, REDIS_PORT and optionally REDIS_USER and REDIS_PASSWORD if your Redis instance is not running on localhost:6379.
RedisInsight is a graphical management tool for Redis. It allows you to view and edit data in Redis, and contains specialized views for looking at the contents of Redis Streams.
You don't need to install or use RedisInsight to be successful with this course, but we'd recommend you give it a try.
Download RedisInsight here (it's free!). Once installed, add a new Redis database and supply the hostname, port and optionally password for the Redis instance that you're using for this course (this will usually be localhost, 6379 and no password).
If you have questions about this repository, you can chat with our teaching assistants on the Redis University Discord Server.
We'd love for you to check out our YouTube channel, and subscribe if you want to see more Redis videos! We also stream regularly on our Twitch.tv channel - follow us to be notified when we're live and check out our events schedule on the Redis Developer site.