
SQA Engineer specializing in backend testing, API automation (RestAssured, Postman), and test automation with Java. Proficient in UI automation (Selenium, POM) and performance testing (JMeter). Experienced in manual, regression, database, and UAT testing, ensuring software quality across various platforms.


Redis is an open-source, in-memory data structure store widely used as a database, cache, and message broker. Its speed, flexibility, and rich feature set make it a core component in modern backend architectures. Redis was developed by Italian computer programmer Salvatore Sanfilippo, also known by his online handle “antirez,” starting in 2009 to solve scalability issues for his startup.
This blog will take you on a journey from basic Redis concepts to advanced, real-world usage patterns, with practical explanations tailored for backend and full-stack developers.
Redis is an in-memory key–value store, meaning data is primarily stored in RAM instead of disk. This allows Redis to achieve extremely low latency (often sub-millisecond).
Redis vs Traditional Databases
Feature | Redis | SQL/NoSQL DB |
|---|---|---|
Storage |
Memory-first |
Disk-first |
Speed |
Extremely fast |
Slower |
Data Types |
Rich |
Limited |
Persistence |
Optional |
Mandatory |
Installing Redis
sudo apt install redis
redis-server
Redis CLI
redis-cli
PING
# PONGRedis stores data as key → value pairs.
4.1 Strings
The simplest and most commonly used type.
SET key value
GET key4.2 Lists
Ordered collections (like arrays or queues).
LPUSH tasks "task1"
RPUSH tasks "task2"
LPOP tasksUse cases:
4.3 Sets
Unordered collections of unique values.
SADD online_users user1 user2
SISMEMBER online_users user1
SMEMBERS online_usersUse cases:
4.4 Hashes
Key–value pairs inside a single Redis key.
HSET user:1 name "John" age 25
HGETALL user:1Use cases:
User profiles
Config objects
Redis supports automatic expiration of keys.
SET otp:1234 "999999" EX 60
TTL otp:1234Use cases:
OTPs
Session expiration
Cache invalidation
Redis supports real-time message broadcasting.
Publisher
PUBLISH notifications "User logged in"
Subscriber
SUBSCRIBE notificationsUse cases:
Flow:
const cached = await redis.get(key);
if (!cached) {
const data = await db.find();
await redis.set(key, JSON.stringify(data), 'EX', 300);RDB (Snapshotting)
AOF (Append Only File)
Best practice: Enable both.
Redis supports atomic operations using MULTI.
MULTI
INCR balance
DECR stock
EXECN.B: Redis transactions guarantee atomic execution but do not support rollback. If one command fails, others still execute. For strict atomic logic, use Lua scripting.
Lua scripts execute atomically inside Redis.
EVAL "return redis.call('INCR', KEYS[1])" 1 counterUse cases:
Using counters + TTL:
INCR user:1:requests
EXPIRE user:1:requests 60 NX
Or using Lua for accuracyStreams are append-only logs.
XADD orders * user_id 1 amount 200
XREAD COUNT 10 STREAMS orders 0Use cases:
While traditional Redis excels at fast key-based access, it does not support SQL-like queries such as filtering, searching, or aggregation. Redis Stack extends Redis with powerful modules—most notably RediSearch, which enables advanced querying and indexing.
What Is Redis Stack?
Redis Stack is an enhanced Redis distribution that includes:
With Redis Stack, Redis evolves from a key–value store into a real-time search and analytics engine.
13.1 Why RediSearch?
RediSearch enables:
This allows Redis to handle many use cases traditionally reserved for SQL or Elasticsearch—but with Redis-level performance.
13.2 Indexing Data in Redis
RediSearch works by creating indexes on Redis data (Hashes or JSON).
Hash Example
HSET user:1 name "John Doe" age 32 role admin salary 5000Create an index:
FT.CREATE users_idx
ON HASH
PREFIX 1 user:
SCHEMA
name TEXT
role TAG
age NUMERIC
salary NUMERIC SORTABLE13.3 Querying with RediSearch
Full-text search
FT.SEARCH users_idx "John"Filter by tag
FT.SEARCH users_idx "@role:{admin}"Numeric range
FT.SEARCH users_idx "@age:[30 40]"Combined conditions (AND)
FT.SEARCH users_idx "@role:{admin} @age:[30 40]"Pagination
FT.SEARCH users_idx "*" LIMIT 0 1013.4 Aggregations (Analytics)
Count users by role:
FT.AGGREGATE users_idx "*"
GROUPBY 1 @role
REDUCE COUNT 0 AS total
Average salary per role:
FT.AGGREGATE users_idx "*"
GROUPBY 1 @role
REDUCE AVG 1 @salary AS avg_salaryThis makes Redis suitable for real-time dashboards and analytics.
13.5 RedisJSON + RediSearch
Redis Stack supports indexing JSON documents:
JSON.SET user:2 $ '{
"name": "Alice",
"age": 29,
"role": "manager"
}'
Index JSON fields:
FT.CREATE users_json_idx
ON JSON
PREFIX 1 user:
SCHEMA
$.name AS name TEXT
$.role AS role TAG
$.age AS age NUMERIC13.6 Vector Search (AI & RAG Use Cases)
RediSearch supports vector similarity search:
FT.CREATE docs_idx
ON HASH
SCHEMA
content TEXT
embedding VECTOR HNSW 1536 TYPE FLOAT32 DISTANCE_METRIC COSINEHSET user:1 name "John Doe" age 32 role admin salary 5000Create an index:
FT.CREATE users_idx
ON HASH
PREFIX 1 user:
SCHEMA
name TEXT
role TAG
age NUMERIC
salary NUMERIC SORTABLERedis starts as a simple key–value store but evolves into a powerful distributed system component when used correctly. From caching and sessions to streams and clustering, Redis plays a crucial role in scalable backend architecture.If you master Redis fundamentals and advanced concepts, you gain a major advantage in building high-performance, real-time applications.