Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

SMOVE

Last updated
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.

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.

127.0.0.1:6379> SADD todo "write" "test"
(integer) 2
127.0.0.1:6379> SMOVE todo done "write"
(integer) 1
127.0.0.1:6379> SMOVE todo done "deploy"
(integer) 0
127.0.0.1:6379> SMEMBERS done
1) "write"

Same as Redis 7.4 and Valkey 8.

SADD, SREM, LMOVE