> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/upstash/redis-js/llms.txt
> Use this file to discover all available pages before exploring further.

# SCARD

> Get the number of members in a set

Returns the cardinality (number of elements) of the set stored at key.

## Usage

```typescript theme={null}
await redis.scard(key);
```

## Parameters

<ParamField body="key" type="string" required>
  The key of the set
</ParamField>

## Response

<ResponseField name="result" type="number">
  The cardinality (number of members) of the set, or `0` if the key does not exist
</ResponseField>

## Examples

### Get set size

```typescript theme={null}
await redis.sadd("myset", "hello", "world", "foo");
const size = await redis.scard("myset");
console.log(size); // 3
```

### Get size of empty set

```typescript theme={null}
const size = await redis.scard("nonexistent");
console.log(size); // 0
```

### Track active sessions

```typescript theme={null}
await redis.sadd("sessions:active", "session1", "session2", "session3");
const activeCount = await redis.scard("sessions:active");
console.log(`Active sessions: ${activeCount}`); // Active sessions: 3
```

### Monitor set size changes

```typescript theme={null}
await redis.sadd("tags", "javascript", "typescript");
console.log(await redis.scard("tags")); // 2

await redis.sadd("tags", "python", "go");
console.log(await redis.scard("tags")); // 4

await redis.srem("tags", "javascript");
console.log(await redis.scard("tags")); // 3
```
