Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Zrem command

Redis Zrem command

Redis Sorted Set

The Redis Zrem command is used to remove one or more members from a sorted set. Members that do not exist are ignored.

Returns an error when key exists but is not of sorted set type.

**Note:** Before Redis version 2.4, ZREM could only remove one element at a time.

Syntax

The basic syntax of the redis Zrem command is as follows:



redis 127.0.0.1:6379> ZREM key member [member ...]

Available Version

= 1.2.0

Return Value

The number of members successfully removed, not including ignored members.

Example



# Test data



redis 127.0.0.1:6379> ZRANGE page_rank 0 -1 WITHSCORES

1) "bing.com"

2) "8"

3) "baidu.com"

4) "9"

5) "google.com"

6) "10"





# Remove a single element



redis 127.0.0.1:6379> ZREM page_rank google.com

(integer) 1



redis 127.0.0.1:6379> ZRANGE page_rank 0 -1 WITHSCORES

1) "bing.com"

2) "8"

3) "baidu.com"

4) "9"





# Remove multiple elements



redis 127.0.0.1:6379> ZREM page_rank baidu.com bing.com

(integer) 2



redis 127.0.0.1:6379> ZRANGE page_rank 0 -1 WITHSCORES

(empty list or set)





# Remove non-existent elements



redis 127.0.0.1:6379> ZREM page_rank non-exists-element

(integer) 0

Redis Sorted Set