Redis – Sorted Set Zcard Command

  • Post author:
  • Post category:Redis
  • Post comments:2 Comments

Redis ZCARD command returns the number of elements stored in a set at a specified key.

Return Value

Integer reply, the cardinality (number of elements) of the sorted set, or 0 if the key does not exist.

Syntax

Following is the basic syntax of Redis ZCARD command.

redis 127.0.0.1:6379> ZCARD KEY_NAME

Example

redis 127.0.0.1:6379> ZADD myset 1 "hello" 
(integer) 1 
redis 127.0.0.1:6379> ZADD myset 1 "foo" 
(integer) 1 
redis 127.0.0.1:6379> ZADD myset 2 "world" 3 "bar" 
(integer) 2 
redis 127.0.0.1:6379> ZCARD myzset 
(integer) 4

This Post Has 2 Comments

Leave a Reply