Boost Your Search Capabilities with RediSearch and RedisJSON – A Hands‑On Guide
This guide introduces RedisMod’s enhanced modules, shows how to install Redis with Docker, demonstrates native JSON storage using RedisJSON, walks through building and querying a full‑text search index with RediSearch—including Chinese support—and compares its performance against Elasticsearch.
RedisMod Overview
RedisMod is a collection of Redis modules that extend its functionality, including RediSearch, RedisJSON, RedisTimeSeries, RedisGraph, RedisBloom, RedisGears, and RedisAI.
Installation
Install Redis with all modules using Docker:
<code>docker pull redislabs/redismod:preview
docker run -p 6379:6379 --name redismod \
-v /mydata/redismod/data:/data \
-d redislabs/redismod:preview</code>RedisJSON
RedisJSON enables native JSON storage. Example commands:
<code>JSON.SET product:1 $ '{"id":1,"productSn":"7437788","name":"小米8","subTitle":"全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待","brandName":"小米","price":2699,"count":1}'
JSON.SET product:2 $ '{"id":2,"productSn":"7437789","name":"红米5A","subTitle":"全网通版 3GB+32GB 香槟金 移动联通电信4G手机 双卡双待","brandName":"小米","price":649,"count":5}'
JSON.SET product:3 $ '{"id":3,"productSn":"7437799","name":"Apple iPhone 8 Plus","subTitle":"64GB 红色特别版 移动联通电信4G手机","brandName":"苹果","price":5499,"count":10}'
</code>Retrieve data with
JSON.GET, query specific fields with dot notation, and check type with
JSON.TYPE.
RediSearch
RediSearch turns Redis into a full‑text search engine with native Chinese support. Create an index for the product JSON data:
<code>FT.CREATE productIdx ON JSON PREFIX 1 "product:" LANGUAGE chinese SCHEMA $.id AS id NUMERIC $.name AS name TEXT $.subTitle AS subTitle TEXT $.price AS price NUMERIC SORTABLE $.brandName AS brandName TAG</code>Search examples:
<code>FT.SEARCH productIdx *
FT.SEARCH productIdx * SORTBY price DESC
FT.SEARCH productIdx RETURN 3 name subTitle price
FT.SEARCH productIdx '@brandName:{小米 | 苹果}'
FT.SEARCH productIdx '@price:[500 1000]'
FT.SEARCH productIdx '@name:小米*'
FT.SEARCH productIdx '黑色'
FT.SEARCH productIdx '@subTitle:红色'
</code>Manage indexes with
FT.DROPINDEXand inspect with
FT.INFO.
Comparison with Elasticsearch
Benchmark results show RediSearch indexing 560 k Wikipedia documents in 221 s versus Elasticsearch’s 349 s (58 % faster). Query throughput reaches 12.5 K ops/sec compared to Elasticsearch’s 3.1 K ops/sec (≈4× faster) with slightly lower latency (8 ms vs 10 ms).
Conclusion
Redis has evolved beyond a cache to a versatile database. RediSearch provides a powerful, high‑performance search option that can replace traditional search engines for many use cases.
Official docs: https://developer.redis.com/howtos/redisjson/
RediSearch manual: https://oss.redis.com/redisearch/
Performance test: https://redis.com/blog/search-benchmarking-redisearch-vs-elasticsearch/
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.