Master Redis modules - RedisJSON, RediSearch, RedisTimeSeries, RedisBloom, and extending Redis functionality
JSON document storage and manipulation.
# Set document
JSON.SET user:1 $ '{"name":"John","age":30,"tags":["redis"]}'
# Get path
JSON.GET user:1 $.name # "John"
JSON.GET user:1 $ # Full document
# Modify
JSON.NUMINCRBY user:1 $.age 1 # Increment
JSON.ARRAPPEND user:1 $.tags '"new"' # Add to array
JSON.SET user:1 $.email '"[email protected]"'
Full-text search and secondary indexing.
# Create index
FT.CREATE idx:users ON JSON PREFIX 1 user:
SCHEMA
$.name AS name TEXT SORTABLE
$.email AS email TAG
$.age AS age NUMERIC SORTABLE
# Search
FT.SEARCH idx:users "@name:John"
FT.SEARCH idx:users "@age:[25 35]"
FT.SEARCH idx:users "@email:{[email protected]}"
# Aggregate
FT.AGGREGATE idx:users "*"
GROUPBY 1 @age
REDUCE COUNT 0 AS count
Time-series data with aggregations.
# Create series
TS.CREATE sensor:temp RETENTION 86400000 LABELS type temperature location office
# Add samples
TS.ADD sensor:temp * 23.5
TS.MADD sensor:temp * 23.5 sensor:humidity * 45
# Query
TS.RANGE sensor:temp - + AGGREGATION avg 3600000 # Hourly avg
TS.MRANGE - + FILTER location=office
Probabilistic data structures.
# Bloom filter
BF.ADD filter:emails "[email protected]"
BF.EXISTS filter:emails "[email protected]" # 1 (might exist)
BF.EXISTS filter:emails "[email protected]" # 0 (definitely not)
# Cuckoo filter (allows delete)
CF.ADD filter:users "user123"
CF.DEL filter:users "user123"
# Count-Min Sketch
CMS.INCRBY sketch item1 5 item2 3
CMS.QUERY sketch item1 # ~5
# redis.conf
loadmodule /opt/redis-stack/lib/rejson.so
loadmodule /opt/redis-stack/lib/redisearch.so
loadmodule /opt/redis-stack/lib/redistimeseries.so
loadmodule /opt/redis-stack/lib/redisbloom.so
docker run -p 6379:6379 redis/redis-stack:latest
docker-compose-stack.yml - Redis Stack with modulesMODULES_GUIDE.md - Complete guideMODULE LIST # Check loaded modules
Fix: Check loadmodule path
FT._LIST # List indexes
Fix: Create index first
| Code | Name | Recovery |
|---|---|---|
| MOD001 | NOT_LOADED | Check loadmodule |
| MOD002 | NO_INDEX | FT.CREATE index |
| MOD003 | SCHEMA_ERR | Fix schema definition |