DECR(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’… DECR β€” the "minus one, bestie" command

okay so you want the tea on decr from the Valkey Command Manual? say less. this is the one that takes an integer key and just... knocks it down by one. and if the key doesn't exist? no drama, it starts from 0 first. iconic behavior honestly.


✨ SYNOPSIS ✨

DECR key

🌸 DESCRIPTION 🌸

so basically DECR decrements the number stored at key by one. that's it. that's the whole vibe. πŸ’–

if the key does not exist, it gets set to 0 before the operation happens, and then the decrement does its thing.

⚠️ bestie listen β€” an error gets returned if the key holds a value of the wrong type, or if it holds a string that can't be represented as an integer. not every string is a number, and DECR will absolutely clock that. πŸ’€

also this operation is limited to 64 bit signed integers, so don't come in here with your giant numbers and expect everything to be fine.

See INCR for extra information on increment/decrement operations. (yes, the whole family, they're all connected, iykyk 🫢)


πŸ’Œ REPLY πŸ’Œ

valkey-protocol(7) Integer reply: the value of the key after decrementing it. so you get the new number back, not the old one. slay.


⚑ COMPLEXITY ⚑

O(1) β€” constant time, no waiting around, she's fast fr fr πŸ”₯


πŸ‘‘ ACL CATEGORIES πŸ‘‘

@fast @string @write


πŸ¦‹ HISTORY πŸ¦‹

  • Available since: 1.0.0 β€” she's been here since the beginning, a true main character 🌈

πŸŽ€ EXAMPLES πŸŽ€

127.0.0.1:6379> SET mykey "10"
OK
127.0.0.1:6379> DECR mykey
(integer) 9
127.0.0.1:6379> SET mykey "234293482390480948029348230948"
OK
127.0.0.1:6379> DECR mykey
(error) ERR value is not an integer or out of range

see that last one? that's the "not an integer or out of range" error doing its little villain arc. 😭 that number is way too big for 64 bit signed integers and DECR said absolutely not.


🌟 SEE ALSO 🌟


okay that's the whole page bestie, go forth and decrement responsibly 🫢✨

9.0.0 β€” dated 2025-10-21 β€” straight from the DECR(3valkey) era. mwah πŸ’‹

πŸ“¦ where this page comes from