Apply Now Apply Now Apply Now
header_logo
Post thumbnail
DATABASE

Redis Stack Tutorial: JSON, Search, and Time-Series in One Database  

By Jebasta

Plain Redis is the fastest in-memory cache in the world. But Redis Stack takes that foundation and adds full-text search, native JSON support, time-series storage, and probabilistic data structures like bloom filters, all accessible through the same Redis connection your app already uses. This Redis Stack tutorial shows you how to run it with Docker, store JSON documents, create a full-text search index, query it, and connect from Python, starting from zero. 

Table of contents


  1. TL;DR Summary
  2. What is Redis Stack?
  3. Redis Stack Tutorial: Installation with Docker
  4. Storing JSON Documents with RedisJSON
  5. Indexing and Searching with RediSearch
  6. Time-Series Data with RedisTimeSeries
  7. Connecting with Python
  8. When to Use Redis Stack
    • 💡 Did You Know?
  9. Common Mistakes to Avoid
  10. Conclusion
  11. FAQs
    • What is Redis Stack? 
    • Is Redis Stack free?
    • What is the difference between Redis and Redis Stack?
    • Do I need to install the modules separately?
    • Can I use Redis Stack with Python? 

TL;DR Summary

  • Redis Stack bundles Redis with four powerful modules: RediSearch, RedisJSON, RedisTimeSeries, and RedisBloom, in a single Docker image.
  • Setup takes under 2 minutes and includes a built-in RedisInsight GUI at port 8001.
  • Redis Stack enables full-text search, secondary indexing, JSON document storage, and time-series queries without adding any new database to your stack.
  • Use Redis Stack when you want Redis as a primary data store with search and analytics, not just a cache.
  • Free to use locally. Redis Cloud offers a managed free tier with 30 MB.

What is Redis Stack?

Redis Stack bundles four Redis modules into a single, easy-to-deploy package: RedisJSON, RediSearch, RedisTimeSeries, and RedisBloom. It also includes RedisInsight, a visualisation tool for understanding and optimising Redis data.

Here is what each module adds:

ModuleWhat It Does
RedisJSONStore, update, and query native JSON documents
RediSearchFull-text search, secondary indexing, and vector similarity search
RedisTimeSeriesEfficient storage and aggregation of time-series metrics
RedisBloomProbabilistic structures: Bloom filters, Cuckoo filters, Count-Min Sketch

The result is a single database that handles caching, search, analytics, and JSON storage without adding separate Elasticsearch, MongoDB, or InfluxDB instances.

Redis Stack sits at the centre of modern backend architectures that need caching, search, and analytics without separate infrastructure for each. HCL GUVI’s Full Stack Development Course and AI Software Development Course are both IITM Pravartak certified and build the backend depth that makes tools like Redis Stack practical in production.

Redis Stack Tutorial: Installation with Docker

Run Redis Stack with one Docker command. Redis listens on port 6379 and RedisInsight (the GUI) runs on port 8001.

docker run -d –name redis-stack -p 6379:6379 -p 8001:8001 -v redis-stack-data:/data redis/redis-stack:latest

Open http://localhost:8001 in your browser to access the RedisInsight GUI where you can inspect keys, run commands, and visualise data without touching the CLI.

Verify the modules loaded successfully by connecting with redis-cli:

docker exec -it redis-stack redis-cli MODULE LIST

You should see search, ReJSON, timeseries, and bf listed. If you see an empty list, the container is still starting — wait 10 seconds and try again.

Storing JSON Documents with RedisJSON

RedisJSON lets you store, update, and query JSON documents natively in Redis without serialising them to strings first.

Store a product document:

JSON.SET product:1001 $ '{"name": "Wireless Keyboard", "category": "electronics", "price": 1299, "stock": 45}'

Read the whole document:

JSON.GET product:1001 $

Update just one field without reading the whole document:

JSON.SET product:1001 $.price 1199

Append to a nested array:

JSON.ARRAPPEND product:1001 $.tags '"sale"' '"bestseller"'

This granular update capability is one of the key advantages RedisJSON has over storing JSON as a plain string: you pay only for what you touch.

Indexing and Searching with RediSearch

RediSearch adds full-text search, secondary indexing, aggregation, and vector similarity search to Redis. You can create indexes on existing Redis hashes and JSON documents and query them with a rich query language without changing your data model.

Create an index over your product JSON documents:

FT.CREATE idx:products ON JSON PREFIX 1 product:
  SCHEMA $.name AS name TEXT WEIGHT 2.0
         $.category AS category TAG
         $.price AS price NUMERIC SORTABLE
         $.stock AS stock NUMERIC

The index automatically picks up every key that starts with product: and keeps itself updated as documents change.

Search for products:

FT.SEARCH idx:products "keyboard" FILTER price 500 2000 SORTBY price ASC LIMIT 0 10

This finds every product matching “keyboard” with a price between 500 and 2000, sorted by price, in a single command. No JOIN, no separate query layer.

MDN

Time-Series Data with RedisTimeSeries

RedisTimeSeries is built for metrics, IoT sensor readings, and application performance data where you need efficient storage and fast aggregation over time ranges.

Create a time series and add readings:

TS.CREATE temp:sensor1 RETENTION 86400000 LABELS location bangalore type temperature
TS.ADD temp:sensor1 * 34.2
TS.ADD temp:sensor1 * 35.1
TS.ADD temp:sensor1 * 33.8

The asterisk uses the current timestamp automatically. The RETENTION value is in milliseconds, so 86400000 keeps 24 hours of data and auto-deletes older readings.

Query the average over the last hour:

TS.RANGE temp:sensor1 -1 + AGGREGATION avg 3600000

Connecting with Python

Install the official Python client:

pip install redis

Connect and use all Redis Stack features:

Python 

import redis
import json

r = redis.Redis(host='localhost', port=6379, decode_responses=True)

r.json().set('product:2001', '$', {
    'name': 'Mechanical Keyboard',
    'category': 'electronics',
    'price': 3499,
    'stock': 12
})

r.ft('idx:products').create_index([
    r.ft.TextField('$.name', as_name='name', weight=2.0),
    r.ft.TagField('$.category', as_name='category'),
    r.ft.NumericField('$.price', as_name='price', sortable=True)
], definition=r.ft.IndexDefinition(prefix=['product:'], index_type=r.ft.IndexType.JSON))

results = r.ft('idx:products').search('mechanical')
for doc in results.docs:
    print(doc.name, doc.price)

When to Use Redis Stack

Use CaseWhy Redis Stack
Product catalogue searchRediSearch replaces Elasticsearch for most mid-scale use cases
Session store plus user profileRedisJSON stores rich user data alongside standard Redis session keys
IoT dashboardRedisTimeSeries aggregates sensor data and serves dashboards in milliseconds
Recommendation feedCombine RedisJSON for item data with RediSearch vector search for similarity
Fraud detectionRedisBloom handles large-scale membership checks with minimal memory

💡 Did You Know?

  • RediSearch is included in Redis Stack and automatically indexes matching existing and new hashes and JSON documents, making it non-intrusive to add to an existing Redis deployment. This means you can add search to an existing Redis-backed application without migrating any data or changing your write path.

Common Mistakes to Avoid

  • Using plain Redis when you need Redis Stack. If your application stores JSON as serialised strings in plain Redis and you need to query fields inside those documents, you are doing work RedisJSON handles natively. Switch to Redis Stack and your query code becomes simpler and faster simultaneously.
  • Not specifying a PREFIX on FT.CREATE. Without a prefix, RediSearch scans every key in Redis to build the index, including your session keys, rate limit counters, and caches. Always scope your index to a specific key prefix that matches only the documents you want indexed.
  • Forgetting RETENTION on time series. Without a retention policy, RedisTimeSeries keeps data forever. For high-frequency sensor data this consumes memory rapidly. Always set a RETENTION value in milliseconds when creating any time series key.

Conclusion

This Redis Stack tutorial covered the full beginner path: running with Docker, storing JSON documents with RedisJSON, creating a search index with RediSearch, aggregating time-series data with RedisTimeSeries, and connecting from Python. Redis Stack gives you a mature, battle-tested foundation for search, analytics, and structured data storage without adding new databases to your architecture.

FAQs

1. What is Redis Stack? 

Redis Stack is an extension of Redis that bundles RediSearch, RedisJSON, RedisTimeSeries, and RedisBloom into a single Docker image, adding full-text search, native JSON storage, time-series analytics, and probabilistic data structures to standard Redis.

2. Is Redis Stack free?

Yes for local use. Redis Stack Server is licensed under the Redis Source Available License 2.0 (RSALv2) or the Server Side Public License (SSPL). Redis Cloud also offers a managed free tier with 30 MB included.

3. What is the difference between Redis and Redis Stack?

Plain Redis handles caching, pub/sub, and basic data structures. Redis Stack adds full-text search, JSON document storage, time-series data, and probabilistic filters on top of the same in-memory engine.

4. Do I need to install the modules separately?

No. The redis/redis-stack Docker image ships with all four modules pre-installed and loaded automatically on startup.

MDN

5. Can I use Redis Stack with Python? 

Yes. The standard redis-py package supports all Redis Stack modules through dedicated command groups like r.json(), r.ft(), and r.ts() with no additional drivers required.

Success Stories

Did you enjoy this article?

Schedule 1:1 free counselling

Similar Articles

Loading...
Get in Touch
Chat on Whatsapp
Request Callback
Share logo Copy link
Table of contents Table of contents
Table of contents Articles
Close button

  1. TL;DR Summary
  2. What is Redis Stack?
  3. Redis Stack Tutorial: Installation with Docker
  4. Storing JSON Documents with RedisJSON
  5. Indexing and Searching with RediSearch
  6. Time-Series Data with RedisTimeSeries
  7. Connecting with Python
  8. When to Use Redis Stack
    • 💡 Did You Know?
  9. Common Mistakes to Avoid
  10. Conclusion
  11. FAQs
    • What is Redis Stack? 
    • Is Redis Stack free?
    • What is the difference between Redis and Redis Stack?
    • Do I need to install the modules separately?
    • Can I use Redis Stack with Python?