0
0
Redisquery~3 mins

Why INCR and DECR for counters in Redis? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could count things perfectly without lifting a finger?

The Scenario

Imagine you are tracking how many people visit your website by writing down each visit on a piece of paper.

Every time someone visits, you add one mark manually.

The Problem

This manual counting is slow and easy to mess up.

You might lose track, count twice, or forget to add a mark.

It becomes a big headache when many people visit quickly.

The Solution

Using INCR and DECR commands in Redis lets you automatically add or subtract from a counter.

This happens instantly and safely, even if many users visit at the same time.

Before vs After
Before
count = count + 1  # manually increase counter
After
INCR visits  # Redis command to increase counter
What It Enables

You can track live counts easily and reliably without mistakes or delays.

Real Life Example

Counting how many times a button is clicked on a website in real time.

Key Takeaways

Manual counting is slow and error-prone.

INCR and DECR automate safe counting in Redis.

This makes live tracking simple and reliable.