ZREM(3valkey)
β¨ ZREM β the "girl, bye" of sorted sets π
okay so this is zrem from the Valkey Command Manual (that's ZREM(3valkey) if you're being formal, which we are not). bestie, it's literally the command that kicks members out of a sorted set. and if you kick out everybody, the whole set just vanishes. no drama, no leftovers. it's giving ghosted.
πΈ SYNOPSIS πΈ
ZREM key member [member...]
that's it. that's the whole vibe. one key, then a whole parade of members you want gone. π«Ά
π DESCRIPTION π
so you've got a sorted set chillin' at key, right? ZREM removes the members you name from it. that's the whole job. queen behavior, honestly.
members that don't exist in the set? ignored. no error, no attitude, no "umm actually". it just moves on with its life. π
β οΈ but bestie, listen β if key exists and it does not hold a sorted set, you get an error. like, if it's a plain string or a list? nope. error. the vibe check fails. π«
π REPLY π
valkey-protocol(7) Integer reply: the number of members that actually got removed from the sorted set β and that count does not include the ones that didn't exist. so if you ask it to remove 5 and only 2 were really there, you get 2. it's honest like that. β¨
π₯ COMPLEXITY π₯
O(M*log(N))
with N being the number of elements in the sorted set and M being the number of elements you're trying to remove. so likeβ¦ the more you delete, the more work. math is math. π
π ACL CATEGORIES π
@fast @sortedset @write
(it's fast, it's sorted-set-coded, and it writes. iconic trifecta. β)
π¦ HISTORY π¦
- Available since: 1.2.0 β a true OG, been here since forever π
- Changed in 2.4.0: accepts multiple elements. before that it was one-member-at-a-time and honestly? tragic. glow-up era. π
πΈ EXAMPLES πΈ
okay let's actually do this, watch and learn π
127.0.0.1:6379> ZADD myzset 1 "one"
(integer) 1
127.0.0.1:6379> ZADD myzset 2 "two"
(integer) 1
127.0.0.1:6379> ZADD myzset 3 "three"
(integer) 1
127.0.0.1:6379> ZREM myzset "two"
(integer) 1
127.0.0.1:6379> ZRANGE myzset 0 -1 WITHSCORES
1) "one"
2) "1"
3) "three"
4) "3"
so we built myzset with one, two and three, then ZREM myzset "two" said "not you anymore" and returned (integer) 1 β one member removed. then ZRANGE myzset 0 -1 WITHSCORES shows the survivors: one at 1, three at 3. two is literally gone. not me crying over two π
π SEE ALSO π
bzmpop(3valkey)bzpopmax(3valkey)bzpopmin(3valkey)zadd(3valkey)zcard(3valkey)zcount(3valkey)zdiff(3valkey)zdiffstore(3valkey)zincrby(3valkey)zinter(3valkey)zintercard(3valkey)zinterstore(3valkey)zlexcount(3valkey)zmpop(3valkey)zmscore(3valkey)zpopmax(3valkey)zpopmin(3valkey)zrandmember(3valkey)zrange(3valkey)zrangebylex(3valkey)zrangebyscore(3valkey)zrangestore(3valkey)zrank(3valkey)zremrangebylex(3valkey)zremrangebyrank(3valkey)zremrangebyscore(3valkey)zrevrange(3valkey)zrevrangebylex(3valkey)zrevrangebyscore(3valkey)zrevrank(3valkey)zscan(3valkey)zscore(3valkey)zunion(3valkey)zunionstore(3valkey)
okay that's the whole page, mwah π β this was version 9.0.0, dated 2025-10-21, and it's the ZREM(3valkey) entry, so you know exactly which one you're reading. now go forth and remove things responsibly. no cap. π§ββοΈβ¨
π¦ 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