DECR(3valkey)
π 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 π
append(3valkey)decrby(3valkey)delifeq(3valkey)get(3valkey)getdel(3valkey)getex(3valkey)getrange(3valkey)getset(3valkey)incr(3valkey)incrby(3valkey)incrbyfloat(3valkey)lcs(3valkey)mget(3valkey)mset(3valkey)msetnx(3valkey)psetex(3valkey)set(3valkey)setex(3valkey)setnx(3valkey)setrange(3valkey)strlen(3valkey)substr(3valkey)
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
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms