w3resource

Redis Sets: SCARD key

Redis SCARD Command

Redis SCARD command is used to return the number of elements stored in the set.

Here are some common uses and scenarios for the "SCARD" command:

  • Counting Members: Retrieve the total count of unique members in a set.
  • Membership Analysis: Analyze the size of groups, such as the number of users in a group or tags on a resource.
  • Capacity Planning: Monitor the size of sets to plan for scaling and resource allocation.
  • Data Validation: Validate the size of collections to ensure they meet expected criteria.
  • Statistical Operations: Use the member count in statistical calculations or reporting.

Syntax:

SCARD KEY_NAME

Available since

1.0.0.

Return Value:

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

Return Value Type:

Integer

Example: Redis SCARD

127.0.0.1:6379> SADD mycolor "Red" "Green"
(integer) 2
127.0.0.1:6379> SADD mycolor "Blue" "Yellow"
(integer) 2
127.0.0.1:6379> SCARD mycolor
(integer) 4

Previous: Redis Sets SADD
Next: Redis Sets SDIFF



Follow us on Facebook and Twitter for latest update.