Set
RESP3prefix: ~ · client type: set / Set / HashSet / frozenset
RESP3 sets encode unordered collections with test-for-existence semantics. Format: ~<count>\r\n followed by count elements. SMEMBERS, SUNION, SDIFF, and SINTER now return sets instead of arrays in RESP3. Clients return native set types (Python set, Ruby Set, Java HashSet) without needing to know the command name.
Details
Sets have the format ~<count>\r\n followed by count RESP elements.
Sets are semantically unordered. The protocol does not enforce that elements are unique, but the spec says implementations should handle duplicates gracefully (typically by inserting into a native Set type which deduplicates automatically).
Client implementations: Python: set() Ruby: Set (standard library) Java: HashSet<V> JavaScript (no native set for arbitrary types): Map with values as true
In RESP2, SMEMBERS returned an *-array. The client had to know the command name to decide whether to return a list or set. RESP3 makes this automatic.
Commands returning sets in RESP3: SMEMBERS, SUNION, SDIFF, SINTER, KEYS (also returns ~), HKEYS (also returns ~).
Wire encoding
~3\r\n+apple\r\n+banana\r\n+cherry\r\n
# represents {apple, banana, cherry} (unordered set)Type information
| Prefix byte | ~ |
| Version | RESP3 |
| Client type | set / Set / HashSet / frozenset |
| Specification | RESP3 specification (GitHub) → |