I am looking to add a search engine to an app with as fast of a response as possible. The users are searching for tickers or company names so it’s a relatively compact data set, so I am wondering if storing all of the names and tickers in redis would be viable instead of querying the database directly.
We use MongoDB if that changes anything.
2
Answers
You can use redis for search if you are storing data as separate Lists or Hashes.
https://redis.io/topics/data-types
In case, you need to perform actions like free text search, redis is not able to do that and you need to keep using MongoDB
Redis can be extended by installing modules.
RediSearch provides indexing, querying and full-text search on hashes and on JSON documents (when using RedisJSON).
You can insert the Tickers or company names in hashes. As Redis is storing everything in memory (the index as well) the search request will be fast.
Here is an example:
Create an index with two fields.
name
andticker
using the TEXT type.(Note that for the ticker we disable the stemming.)
Insert a company in a HASH:
I can search by using the ticker:
Or search with the company name: