ZREM

Since 1.1.0Sorted sets

Syntax

ZREM key member [member ...]
  • Flags: write
  • ACL categories: @slow, @sortedset, @write
  • Arity: -3

Removes one or more members from the sorted set at key. Members that are not in the set are ignored, and a member named twice is removed once. A sorted set left empty is deleted.

To remove members by position or score instead of by name, use ZREMRANGEBYRANK, ZREMRANGEBYSCORE or ZREMRANGEBYLEX. To remove the lowest or highest members and get them back, use ZPOPMIN or ZPOPMAX.

Reply

  • The number of members removed, not counting those that were not there.
  • 0 if the key does not exist.

Errors

  • WRONGTYPE Operation against a key holding the wrong kind of value if the key holds something other than a sorted set.
  • ERR wrong number of arguments for 'zrem' command if no member is given.

Examples

> ZADD z 1 a 2 b 3 c
(integer) 3
> ZREM z a nope a
(integer) 1
> ZREM z b c
(integer) 2
> EXISTS z
(integer) 0
> ZREM missing a
(integer) 0