English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Redis Smove command moves the specified member element member from the source set to the destination set.
SMOVE is an atomic operation.
If the source set does not exist or does not contain the specified member element, the smove command does not perform any operation and only returns 0. Otherwise, the member element is removed from the source set and added to the destination set.
If the destination set already contains the member element, the smove command simply deletes the member element from the source set.
If the source or destination is not a set type, an error is returned.
The basic syntax of the redis smove command is as follows:
redis 127.0.0.1:6379> SMOVE SOURCE DESTINATION MEMBER
>= 1.0.0
If the member element is successfully removed, return 1 . If the member element is not a member of the source set and no operation is performed on the destination set, then 0 is returned.
redis 127.0.0.1:6379> SADD myset1 "hello" (integer) 1 redis 127.0.0.1:6379> SADD myset1 "world" (integer) 1 redis 127.0.0.1:6379> SADD myset1 "bar" (integer) 1 redis 127.0.0.1:6379> SADD myset2 "foo" (integer) 1 redis 127.0.0.1:6379> SMOVE myset1 myset2 "bar" (integer) 1 redis 127.0.0.1:6379> SMEMBERS myset1 1) "World" 2) "Hello" redis 127.0.0.1:6379> SMEMBERS myset2 1) "foo" 2) "bar"