SMOVE
SMOVE source destination member
- Group
- Set
- Complexity
- O(1)
- Arity
- 4 (exactly, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SMOVE removes member from the set at source and adds it to the set at
destination in one atomic step. destination is created if it does not
exist, and source is deleted when its last member leaves. If member is
already in destination, it is only removed from source.
When source and destination are the same key, nothing changes; the reply
still tells you whether member is in the set.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Member moved | Integer 1 |
Same |
Member not in source, or source does not exist |
Integer 0 |
Same |
SMOVE replies with a WRONGTYPE error if source exists and is not a set,
or if destination exists and is not a set. A missing source replies 0
without looking at destination.
Examples
Section titled “Examples”127.0.0.1:6379> SADD todo "write" "test"(integer) 2127.0.0.1:6379> SMOVE todo done "write"(integer) 1127.0.0.1:6379> SMOVE todo done "deploy"(integer) 0127.0.0.1:6379> SMEMBERS done1) "write"Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.