Use SADD to add one or more members to a set, creating it when the key does not exist.
A set holds unique, unordered members, so adding a member that is already there changes nothing, and the reply counts only the members that were actually new. That count is what makes the command a cheap deduplicator: a reply of 1 means this caller was the first to see the value, which is enough to decide whether to process an event or ignore it as a repeat.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
<member> | Yes | Yes | Member name. |
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Integer |
| RESP3 | Integer |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.