Git Product home page Git Product logo

ru203's Introduction

RU203: Querying, Indexing, and Full-text Search with Redis

Introduction

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:

  1. Clone this git repository
  2. Get a Redis Stack database instance and load the sample data into it
  3. 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.

Option 1: Run Redis Stack locally with Docker (Best option for beginners)

First, make sure you have Docker installed.

1. Start Redis Stack

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.

2. Load the sample data

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.

3. Create the indexes

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).

Option 2: Install Redis Stack Locally with a Package Manager

1. Install Redis Stack

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.

2. Load the sample data

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.

3. Create the indexes

To create the indexes, first start the Redis CLI:

redis-cli

Then paste in the index creation commands (see the next section for details).

Building indexes

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"

Optional (but Recommended): RedisInsight

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.

You're Ready!

Now, you're ready to take the course.

If you aren't signed up yet, visit the course signup page to register!

Appendix: The Data Model

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  |
|              |
+--------------+

Subscribe to our YouTube Channel / Follow us on Twitch

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.

ru203's People

Contributors

abrookins avatar banker avatar justincastilla avatar suzeshardlow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ru203's Issues

Update dataset and course to use geo aggregations.

This course should be updated to use geo aggregations (find stuff near somewhere). This will require an update to the data set (maybe add some library locations) and should include both radius and the new polygon geo functionality when that's released.

These should be added as text segments rather than new videos. We can also point to any video / live stream / demo repos that we put out as well.

Amend the `docker-compose.yml` file for this course to use the Redis Stack container and re-test

This course currently uses an older version of the RediSearch container in its docker-compose.yml file.

Amend the docker-compose.yml file for this course to use the Redis Stack container and test that data loading process, the index generation commands and sample query in README.md all still work.

Don't rename the container - leave it named redis-search.

This is part of our participation in Hacktoberfest 2022. Learn how to complete this issue here: https://redis.io/community/hacktoberfest/

Need help or want to talk to us? Join us on Discord where we have a dedicated Hacktoberfest channel: https://discord.gg/ueQwKUh5Z3

If you're interested in taking this issue on, please mention @simonprickett and @SuzeShardlow in the comments and ask to be assigned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.