INCR adds 1 to a number in Valkey® and DECR takes 1 away, in one step that never loses a count. This guide counts visitors.
Type the commands at the valkey-cli prompt. To open it, run valkey-cli in a terminal.
Note: Every command and output on this page is real, run on Valkey 9.2 on an Apple silicon Mac with macOS 26.
Syntax
INCR key
DECR key
INCRBY key increment
DECRBY key decrement
key: the counter. If it doesn’t exist, Valkey starts it at 0.incrementanddecrement: the whole number to add or take away.
From the INCR (opens in a new tab), DECR (opens in a new tab), INCRBY (opens in a new tab) and DECRBY (opens in a new tab) documentation.
Step 1: Count Up with INCR
INCR visitors
(integer) 1
visitors didn’t exist, so Valkey started at 0 and added 1. Each INCR adds 1 more:
INCR visitors
(integer) 2
Step 2: Count Down with DECR
DECR visitors
(integer) 1
Step 3: Change by More Than One
INCRBY visitors 10
(integer) 11
DECRBY visitors 5
(integer) 6
GET visitors
"6"
Every command replies with the new value. The counter itself is a string, so GET shows "6".
Step 4: Counters Need Whole Numbers
SET name "Ana"
OK
INCR name
(error) ERR value is not an integer or out of range
A key that holds text can’t be counted. Valkey replies with this error and leaves the key unchanged.

Clean Up
DEL visitors name
(integer) 2
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Reading the count, adding 1 in your app and saving it back | Two clients can save the same number, so a count is lost | Use INCR, which counts in one step |
Using INCR with a decimal | Valkey refuses it | Use INCRBYFLOAT |
FAQ
How high can a counter go?
To 9223372036854775807. The INCR documentation (opens in a new tab) says counters are 64-bit signed integers.
Can a counter go below zero?
Yes. DECR and DECRBY go negative. To stop at zero, use INCREX with LBOUND 0 (Valkey 9.2 and later).
Conclusion
INCR and DECR change a counter by 1, and INCRBY and DECRBY by any whole number, each in one atomic step.
Related
- Valkey Tutorial — Part 4: Strings and Counters
- Valkey Tutorial — Part 2: Your First Valkey Commands with valkey-cli
Additional Resources
- INCR (opens in a new tab)
- DECR (opens in a new tab)
- INCRBY (opens in a new tab)
- DECRBY (opens in a new tab)
- Valkey strings (opens in a new tab)
Valkey® is a registered trademark of LF Projects, LLC. Redis® is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. Other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with the Valkey project, LF Projects or Redis Ltd., and isn’t endorsed, supported or certified by them.
0 comments