> ## 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.

# SPOP

> Remove and return one or more random members from a set

Removes and returns one or more random members from the set stored at key.

## Usage

```typescript theme={null}
await redis.spop(key);
await redis.spop(key, count);
```

## Parameters

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

<ParamField body="count" type="number">
  The number of members to pop. If not specified, one member is popped
</ParamField>

## Response

<ResponseField name="result" type="TData | TData[] | null">
  * When `count` is not specified: Returns the removed member, or `null` if the set is empty
  * When `count` is specified: Returns an array of removed members (may be empty if the set is empty)
</ResponseField>

## Examples

### Pop a single member

```typescript theme={null}
await redis.sadd("myset", "one", "two", "three");
const member = await redis.spop("myset");
console.log(member); // "one" (or "two" or "three")
```

### Pop multiple members

```typescript theme={null}
await redis.sadd("numbers", "1", "2", "3", "4", "5");
const members = await redis.spop("numbers", 3);
console.log(members); // ["1", "3", "5"] (random selection)
```

### Pop from empty set

```typescript theme={null}
const member = await redis.spop("nonexistent");
console.log(member); // null
```

### Random prize selection

```typescript theme={null}
await redis.sadd("prizes", "car", "bike", "laptop", "phone");
const winner = await redis.spop("prizes");
console.log(`Winner gets: ${winner}`);
```

### Pop more members than exist

```typescript theme={null}
await redis.sadd("small", "a", "b");
const members = await redis.spop("small", 10);
console.log(members); // ["a", "b"] (returns all available members)
```
