DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

Follow publication

Searching Nobel winners using Redis

satish1v
DevOps.dev
Published in
4 min readJun 22, 2022

--

Photo by Evgeni Tcherkasski on Unsplash

Redis is a phenomenal cache, and I sometimes have heard it as a synonym for the cache. Well, that's just scratching the surface of an in-memory database.

In this Blog Post, I will introduce how to use Redis as a Seach engine and get an ultra-fast search result with a new, improved dotnet library — Redis OM.

Dataset

I will use a modified version of the Nobel Winners database from nobelprize.org.

You can explore the Modified dataset here.

Installation

You can use Redis Cloud if you don't want to install anything but Redis also provide a Redis Distribution.

docker run -p 6379:6379 -p 8001:8001 redis/redis-stack

Once the Redis is running locally, you can download the RedisInsight. Which can provide UI for viewing the data

Create the Project

To create a dotnet project. I have used the following command.

Adding a project is orthogonal to this blog since you can download the code for learning from the Github Repo.

Let's start our Project with the Data model and Index the Data.

Create your First Index

The first step in understanding the indexing is to understand the Data which needs to understand.

Data consists of Name, Category, and Motivation which are searchable, and we can always sort by Year and share.

With Redis OM, You can model your data and declare indexes using minimal code.

You can use the attributes the Indexed and Searchable.Indexed is used for indexing, whereas the searchable is for Full-text search.

Now index the data from the JSON file to Redis.

Indexing is a four-step process.

  1. Get the Data from the Noble.json and deserialize it to a List object
  2. Connect to the Redis stack and hold the connection
  3. Create an index with the class
  4. Insert the Data into a Redis

Once the Data ingest is complete, you can verify the same in Redis Insight

RedisInsight

RedisInsight is a UI provided by the Redis team to interact with Redis. I highly recommend anyone to download the same.

It provides an easy view of the document and editor to write native queries. You can download it from here.

Create API and Initialize the Connection

As a next step, we will create an API and initialize the Redis connection with the Asp.net core DI.

I use FastEndpoints for most of my projects, so we have registered the same.

Get the latest records by Year.

Redis Om allows querying the database using the known technique. Let us Get all the records ordered by the latest Year and take only the 30 records.

You can use the standard Linq. In this case, you can use skip and Take to get the records with the paging.

Full-Text Search with Name

To enable full-text search on a field, you need to decorate the field with a Searchable attributes.

You can use the First name with the Where clause with searchable, and you can do a full-text search.

Aggregation Search

You can do aggregation and data analysis on the data using the Redis Aggregation function.

In this example, let us find the average age for getting the Noble price so we can calm the anxiety of a few young scientists.

You can find all the functions and Usages here

References and Next Steps

You can Host it easily using Redis Cloud.

You can learn more about Redis Stack and Redis OM here

To get the Repo of this Project.

This post is in collaboration with Redis.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

No responses yet