Redis - 命令 Scard



Redis SCARD 命令用於返回儲存在集合中的元素數。

返回值

整數答覆、集合的基數(元素數)或者鍵不存在時為 0。

語法

以下為 Redis SCARD 命令的基本語法。

redis 127.0.0.1:6379> SCARD KEY_NAME

示例

redis 127.0.0.1:6379> SADD myset "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "foo" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset "hello" 
(integer) 0 
redis 127.0.0.1:6379> SCARD myset 
(integer) 2
redis_sets.htm
廣告