# SDIFF

> Return the members of the first set that are not in any of the other sets.

URL: https://docs.hotkv.com/commands/sdiff/

```
SDIFF key [key ...]
```

- Group: Set
- Complexity: O(N) where N is the total number of members in all given sets
- HotKV Cloud: all plans
- On-Premise: no license needed

`SDIFF` returns the members of the set at the first `key` that are not in any
of the sets at the following keys. Missing keys count as empty sets, so a
missing first key gives an empty result. To store the result, use
[SDIFFSTORE](https://docs.hotkv.com/commands/sdiffstore/index.md).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Success | Array of bulk strings (empty if nothing remains) | Set of bulk strings |

`SDIFF` replies with a `WRONGTYPE` error if any of the keys holds a value that
is not a set.

## Examples

```
127.0.0.1:6379> SADD a "x" "y" "z"
(integer) 3
127.0.0.1:6379> SADD b "y"
(integer) 1
127.0.0.1:6379> SADD c "z" "w"
(integer) 2
127.0.0.1:6379> SDIFF a b c
1) "x"
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[SDIFFSTORE](https://docs.hotkv.com/commands/sdiffstore/index.md), [SINTER](https://docs.hotkv.com/commands/sinter/index.md), [SUNION](https://docs.hotkv.com/commands/sunion/index.md),
[ZDIFF](https://docs.hotkv.com/commands/zdiff/index.md)