YouTip LogoYouTip

Sets Spop

# Redis Spop Command [!(#) Redis Sets](#) The Redis Spop command is used to remove one or more random elements from a set stored at a specified key. After removal, it returns the removed elements. This command is similar to the (#) command, but SPOP removes the random elements from the set and returns them, while Srandmember only returns random elements without making any changes to the set. ### Syntax The basic syntax of the Redis Spop command is as follows: SPOP key The count parameter is available in version 3.2+. ### Available Since >= 1.0.0 ### Return Value The removed random elements. When the set does not exist or is empty, nil is returned. ### Example redis> SADD myset "one"(integer) 1 redis> SADD myset "two"(integer) 1 redis> SADD myset "three"(integer) 1 redis> SPOP myset "one" redis> SMEMBERS myset 1) "three"2) "two" redis> SADD myset "four"(integer) 1 redis> SADD myset "five"(integer) 1 redis> SPOP myset 31) "five"2) "four"3) "two" redis> SMEMBERS myset 1) "three" redis> [!(#) Redis Sets](#)
← C Function FscanfC Function Rewind β†’