RediSearch Quick Start

RediSearch adds a secondary index, a query engine, and a full-text search to Redis

Step 1: Add modules

Step 2: Connect

Download the “Redis Insight” desktop
tool to connect and interact

Mac | Windows | Linux
 

1. Register and subscribe

Getting started with Redis Cloud Essentials

To get started with Redis Enterprise Cloud Essentials, visit https://redislabs.com/try-redis-modules-for-free and fill out the form:

Fill out form

Once you click “Get Started,” we will send you an email with a link to activate your account and complete your signup process.


Adding your Redis Enterprise Cloud Essentials subscription

  1. In the Redis Enterprise Cloud menu, click Subscriptions
  2. At the bottom of the page, click the “+” sign, as shown below:
     
    Click the + sign
  3. Select your subscription configuration as shown here:

For the cloud provider, select Amazon AWS

Select Amazon AWS
The (1) arrow indicates where to choose AWS as your cloud provider for Redis Enterprise Cloud Essentials.

Select a region
The (2) arrow shows where to choose the ap-south-1 cloud region.

In the Redis Enterprise Cloud service levels, select the Redis Enterprise Cloud Essentials 30MB/1 Database level and click Create:

Select the Redis Enterprise Cloud Essentials 30MB/1 Database level and click Create
The (3) arrow shows how to create your first free database with the name “demotest”.

2. Create a Database with Modules

Once you create a subscription, you are ready to create a database with modules enabled. As shown below, enter a name for the database you want to create:

Enter the database name
The (4) arrow shows where to enter the database name. The (5) arrow indicates where to enable modules on Redis Enterprise Cloud Essentials.

Move the toggle to select the module you want. You can choose one module at a time under Redis Enterprise Cloud Essentials. Please note that multiple modules capabilities are currently available only in Redis Cloud Pro.

Select the RediSearch module
The (6) arrow shows where to select the RediSearch module in Redis Enterprise Cloud Essentials.

Let’s go ahead and choose “RediSearch” as our first module. Click “Activate”:

Activate your new database
The (7) arrows shows where to Activate your new database.

The database will remain in “Pending” status until the process of configuring your new Redis database is completed. When the database is created, you will be able to see all the database settings, including:

  • Endpoint: The address you use to connect to the database.
  • Redis password: The password you must use in your application to connect to the database.

Copy the database endpoint
The (8) arrows shows where to copy the database endpoint (redis-16333.c212.ap-south-1.1.ec2.cloud.redislabs.com:16333) for future reference.

3. Connect to the Database

Using RedisInsight

RedisInsight is an intuitive and efficient GUI for Redis, allowing you to interact with your databases and manage your data—with built-in support for most popular Redis modules. The free non-commercial add-on provides tools to analyze the memory, profile the performance of your database, and guide you toward better Redis usage.

Learn more about RedisInsight here!

RedisInsight provides built-in support for the RedisJSON, RediSearch, RedisGraph, Redis Streams, and RedisTimeSeries modules to make it even easier to query, visualize, and interactively manipulate search indexes, graphs, streams, and time-series data. Used properly, RedisInsight can make the experience of using modules with Redis Enterprise Cloud Essentials even smoother. 

A full-featured desktop GUI client, RedisInsight is available for Windows, macOS, and Linux and is fully compatible with Redis Enterprise. It works with any cloud provider as long as you run it on a host with network access to your cloud-based Redis server. RedisInsight makes it easy to discover cloud databases and configure connection details with a single click. It allows you to automatically add Redis Enterprise Software and Redis Enterprise Cloud databases. 

Local installation of RedisInsight:

To use RedisInsight on a local machine, download it for Windows, Mac, or Linux from the RedisInsight page on the RedisLabs website:

Click “Download” to open up a form that allows you to select the operating system of your choice. For example, let’s assume that you want to install RedisInsight on your macOS machine. Choose “Mac OS” as a platform as shown here:

 

Mac OS    Windows    Linux

 

Fill out the rest of the form and click “Download.” Please note that the package name is the combination of the platform and version as shown here:

redisinsight-<platform>-<version>

Running RedisInsight

Click on the RedisInsight executable and install it in your system.

Click on the RedisInsight executable

Head over to your web browser and go to http://localhost:8001


Using RedisInsight with Docker

You can also run RedisInsight inside Docker containers. Visit https://hub.docker.com/r/redislabs/redisinsight/tags to find the latest Docker image available over DockerHub.

$ docker run -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest

Head over to your web browser and go to http://localhost:8001

Congratulations! You have successfully installed RedisInsight and are now ready to inspect your Redis data, monitor database health, and perform runtime server configuration with this browser-based management interface for your Redis deployment.

Once you accept the EULA and click “Confirm,” you are ready to add Redis databases, as shown here:

Accept the EULA and click Confirm

Select “ADD REDIS DATABASE” and then “Add Database”:

Select ADD REDIS DATABASE and then Add Dadtabase

Enter the requested details, including Name, Host (endpoint), Port, and Password in the form, as shown below. You can skip username for now. Then click “ADD REDIS DATABASE”:

Enter the requested details

Click on the pop-up box to see the RedisInsight dashboard:

Click on the pop-up box

How to use RedisInsight to run the Redis CLI

Finally, although RedisInsight is a great GUI, sometimes you want to work directly in the command-line interface (CLI). To do so, click “CLI” in the  menu on the left side of the RedisInsight UI:

 

The arrow highlights CLI option on RedisInsight

Then paste the appropriate Redis commands in the command section, marked with “>>” as shown below, and press Enter.

The (2) arrow points to where to set the string value of a key.

You can see the output displayed at the top of the screen. If it says “OK,” the command was executed successfully.

Now that RedisInsight is installed, we’re ready to look at individual Redis modules and see how they work with Redis Enterprise Cloud Essentials.

4. RediSearch

To begin, let’s create a basic dataset based on movies information, which we will use to show how to:

  1. Insert data
  2. Create an index
  3. Query data

1. Insert data into RediSearch

We are now ready to insert some data. This example uses movies data stored as Redis Hashes, so let’s insert a couple of movies:

> HSET movies:11002 title "Star Wars: Episode V - The Empire Strikes Back" plot "Luke Skywalker begins Jedi training with Yoda." release_year 1980 genre "Action" rating 8.7 votes 1127635

(integer) 6 

> HSET movies:11003 title "The Godfather" plot "The aging patriarch of an organized crime dynasty transfers control of his empire to his son." release_year 1972 genre "Drama" rating 9.2 votes 1563839 

(integer) 6

Your Redis Enterprise Cloud database now contains two Hashes. It is simple to retrieve information using the HMGET command, if you know the key of the movies (movies:11002):

> HMGET movies:11002 title rating

1) "Star Wars: Episode V - The Empire Strikes Back"
2) "8.7"

2. Create an index in RediSearch

To be able to query the hashes on the field for title, say, or genre, you must first create an index. To create an index, you must define a schema to list the fields and their types that are indexed, and that you can use in your queries.

Use the FT.CREATE command to create an index, as shown here:

> FT.CREATE idx:movies ON hash PREFIX 1 "movies:" SCHEMA title TEXT SORTABLE release_year NUMERIC SORTABLE rating NUMERIC SORTABLE genre TAG SORTABLE

OK

 In the command above, we:

  • Create an index named idx:movies
  • Used a schema made up of four fields:
    • title
    • release_year
    • rating
    • genre

Before running queries on our new index, though, let’s take a closer look at the elements of the FT.CREATE command:

  • idx:movies: the name of the index, which you will use when doing queries
  • ON hash: the type of structure to be indexed. (Note that RediSearch 2.0 supports only the Hash structure, but this parameter will allow RediSearch to index other structures in the future.)
  • PREFIX 1 “movies:”: the prefix of the keys that should be indexed. This is a list, so since we want to index only movies:* keys the number is 1. If you want to index movies and TV shows with the same fields, you could use: PREFIX 2 “movies:” “tv_show:”
  • SCHEMA …: defines the schema, the fields, and their type to index. As you can see in the command, we are using TEXT, NUMERIC, and TAG, as well as SORTABLE parameters.

The RediSearch 2.0 engine will scan the database using the PREFIX values, and update the index based on the schema definition. This makes it easy to add an index to an existing application that uses Hashes, there’s no need to change your code.

3. Search the movies in the RediSearch index

You can now use the FT.SEARCH to search your database, for example, to search all movies sorted by release year:

>  FT.SEARCH idx:movies * SORTBY release_year ASC RETURN 2 title release_year
1) (integer) 2
2) "movies:1003"
3) 1) "release_year"
   2) "1972"
   3) "title"
   4) "The Godfather"
4) "movies:1002"
5) 1) "release_year"
   2) "1980"
   3) "title"
   4) "Star Wars: Episode V - The Empire Strikes Back"

You can also search “action” movies that contain “star” in the index (in our sample index, the term “star” will occur only in the title):

>  FT.SEARCH idx:movies "star @genre:{action}" RETURN 2 title release_year
1) (integer) 1
2) "movies:1002"
3) 1) "title"
   2) "Star Wars: Episode V - The Empire Strikes Back"
   3) "release_year"
   4) "1980"

The FT.SEARCH command is the base command to search your database, it has many options and is associated with a powerful and rich query syntax that you can find in the documentation. (Note: You can also use the index to do data aggregation using the FT.AGGREGATE command.)

Learn more about RediSearch in the Getting Started with RediSearch 2.0 tutorial on GitHub.


See what others are building