This repository contains example data and setup instructions for the Redis University course RU203: Querying, Indexing, and Full-Text Search with Redis.
To take this course, you'll first need do the following:
- Clone this git repository
- Get a Redis Stack database instance and load the sample data into it
- Build the search indexes by running the index creation commands provided
Need help getting started? Stop by the Redis University Discord server.
To get Redis Stack, we recommend either launching it from Docker or installing and running it locally using your operating system's package manager.
First, make sure you have Docker installed.
Next, run the following command from your terminal:
docker-compose up -d
This will launch a Redis Stack instance. The instance will be listening on localhost port 6379.
When you're done with this container, stop it like so:
docker-compose down
Redis persists data to the redisdata
folder as an append only file. This is reloaded whenever you restart the container.
The commands that load the sample data are in the file commands.redis
, which is part of this git repository. To load this data, run the following command:
docker exec -i redis-search redis-cli < commands.redis > output.txt
Check the "output" file for "Invalid" responses.
grep Invalid output.txt
If you have any "Invalid" responses, you might not have installed Redis Stack properly. If you have any problems, find us on our Discord channel.
To create the indexes, first start the Redis CLI:
docker exec -it redis-search redis-cli
Then paste in the index creation commands (see the next section for details).
Follow the instructions for your operating system to install Redis Stack. Choose the redis-stack
package containing RedisInsight, don't use the redis-stack-server
package.
- Instructions for macOS users
- Instructions for Linux users
- Instructions for Windows users -- requires Docker.
The commands that load the sample data are in the file commands.redis
, which is part of this git repository. To load this data, run the following command from your terminal:
redis-cli < commands.redis > output.txt
This assumes that you have redis-cli
in your path.
Check the "output" file for "Invalid" responses.
grep Invalid output.txt
If you have any "Invalid" responses, you might not have Redis Stack installed properly. If you have any problems, find us on our Discord channel.
To create the indexes, first start the Redis CLI:
redis-cli
Then paste in the index creation commands (see the next section for details).
This data ships without RediSearch indexes, so you need to create them yourself.
We're going to give you all the commands you need to create these indexes, but before you run these index commands, make sure you're in the redis CLI:
$ redis-cli
Then run the following commands:
FT.CREATE books-idx ON HASH PREFIX 1 ru203:book:details: SCHEMA isbn TAG SORTABLE title TEXT WEIGHT 2.0 SORTABLE subtitle TEXT SORTABLE thumbnail TAG NOINDEX description TEXT SORTABLE published_year NUMERIC SORTABLE average_rating NUMERIC SORTABLE authors TEXT SORTABLE categories TAG SEPARATOR ";" author_ids TAG SEPARATOR ";"
FT.CREATE users-idx ON HASH PREFIX 1 ru203:user:details: SCHEMA first_name TEXT SORTABLE last_name TEXT SORTABLE email TAG SORTABLE escaped_email TEXT NOSTEM SORTABLE user_id TAG SORTABLE last_login NUMERIC SORTABLE
FT.CREATE authors-idx ON HASH PREFIX 1 ru203:author:details: SCHEMA name TEXT SORTABLE author_id TAG SORTABLE
FT.CREATE authors-books-idx ON HASH PREFIX 1 ru203:author:books: SCHEMA book_isbn TAG SORTABLE author_id TAG SORTABLE
FT.CREATE checkouts-idx ON HASH PREFIX 1 ru203:book:checkout: SCHEMA user_id TAG SORTABLE book_isbn TAG SORTABLE checkout_date NUMERIC SORTABLE return_date NUMERIC SORTABLE checkout_period_days NUMERIC SORTABLE geopoint GEO
Now try a sample search query to find the authors of a book titled "You Can Draw Star Wars":
FT.SEARCH books-idx "@title:You Can Draw Star Wars" return 1 authors
Redis Stack should find one book, with "Bonnie Burton" as the author:
1) (integer) 1
2) "ru203:book:details:9780756623432"
3) 1) "authors"
2) "Bonnie Burton"
RedisInsight is a graphical tool for viewing data in Redis and managing Redis server instances. You don't need to install it to be successful with this course, but we recommend it as a good way of viewing data stored in Redis.
To use RedisInsight, you'll need to download it then point it at your Redis instance.
If you're using the Docker Compose file provided with the course to run Redis, you can access a web based version of RedisInsight without installing the desktop version. Find it at http://localhost:8001
.
Now, you're ready to take the course.
If you aren't signed up yet, visit the course signup page to register!
The queries in this repository rely on a data model composed of Redis hashes. The entities in this data model include books, authors, library checkouts, and users. The following diagram represents this data model:
Authors
+--------------+
| name | Author-Books
| | +----------------+
| author_id +------------+ author_id |
| | | |
+--------------+ +---+ book_isbn |
| | |
Users | +----------------+
+--------------+ |
| first_name | |
| | |
| last_name | | Checkouts
| | | +------------------------+
| email | +----|--+ user_id |
| | | | | |
| user_id +---+ +--+ book_isbn |
| | | | |
| last_login | | | checkout_date |
| | | | |
+--------------+ | | checkout_length_days |
| | |
Books | | geopoint |
+--------------+ | | |
| isbn +--------+ +------------------------+
| |
| title |
| |
| subtitle |
| |
| thumbnail |
| |
| description |
| |
| categories |
| |
| authors |
| |
| author_ids |
| |
+--------------+
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.